Crossed Posted November 23, 2020 Posted November 23, 2020 Hi, I just have a simple script that runs on a while loop and only needs to run once every 10 minutes while active. I'm trying to use the sleep(1000 * 600) function for the 10 minute pause but it appears to max out at 4 minutes and 15 seconds. It works fine up to that point, so setting sleep(1000*240) sleeps for exactly 4 mintues. But any miliseconds that pushes it over 4 min 15 seconds still fires at exactly 4:15. Any idea what is going on, and if there is a way to actually put a script to sleep for 10 minutes at a time? Thanks!Â
jitb Posted November 23, 2020 Posted November 23, 2020 Hmmm I never thought to used sleep for any thing that long I use #include <Date.au3> Local $i_End, $i_Hours, $i_Mins, $i_Secs, $i_Begin $i_Begin = TimerInit() ... $i_End = TimerDiff($iBegin) _TicksToTime($iEnd, $i_Hours, $i_Mins, $i_Secs) $Dummy03 = StringFormat("%02d:%02d:%02d", $i_Hours, $i_Mins, $i_Secs) If $Dummy03 > '00:04:05' Then ExitLoop Â
Nine Posted November 23, 2020 Posted November 23, 2020 Cannot replicate your issue. I ran this and no problem : #include <Constants.au3> $hTimer = TimerInit() Sleep (10*1000*60) MsgBox ($MB_SYSTEMMODAL,"",round(TimerDiff($htimer)/(1000*60),1))  âThey did not know it was impossible, so they did itâ â Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text  Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker  Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC  HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet  Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector  Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF  Multi-Threading Made Easy Interface Object based on Tag Â
Moderators Melba23 Posted November 23, 2020 Moderators Posted November 23, 2020 Crossed, As explained in the Help file, the maximum Sleep() is 2147483647 milliseconds, which is around 24 days. So there must be something else in your script which is triggering at 4:15. I suggest posting your script - see here how to do it - so we can take a look. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
JockoDundee Posted November 23, 2020 Posted November 23, 2020 Local $i_End, $i_Hours, $i_Mins, $i_Secs, $i_Begin $i_Begin = TimerInit() While True $i_End = TimerDiff($iBegin) _TicksToTime($iEnd, $i_Hours, $i_Mins, $i_Secs) $Dummy03 = StringFormat("%02d:%02d:%02d", $i_Hours, $i_Mins, $i_Secs) If $Dummy03 > '00:04:05' Then ExitLoop WEnd @jitb, your method of waiting 4:15 is not ideal.  It does a lot of needless work every loop iteration.  Without a sleep inside it, it will throttle one CPU.  If you really just need to unconditionally wait 4 min and 15 seconds, you are better off with just the simple Sleep(). If you need to wait but also need to check on things at the same time you can do can just use TimeDiff compared with (4.5*60*1000) in a while loop with a sleep(10).   Code hard, but donât hard code...
GokAy Posted November 23, 2020 Posted November 23, 2020 (edited) @Crossed, I am not sure why you can't set beyond 4:15, but why you don't see a difference beyond 4:15 with few milliseconds could be related to your system's TimerResolution. Which is usually between 15-16 milliseconds when not required to save energy. So , you may be off by 15-16 ms at most for any single sleep() issued. https://docs.microsoft.com/en-us/windows/win32/multimedia/timer-resolution You can check it with a tool like http://www.lucashale.com/timer-resolution/. Can also set a value while it runs, but not sure if it will affect the outcome. A little test: test() func test() for $i = 1 to 20 step 1 local $hTimer = TimerInit() sleep($i) ConsoleWrite("test1 " & $i & " elapsed: " & TimerDiff($hTimer) & @crlf) Next for $i = 1 to 1001 step 100 local $hTimer = TimerInit() sleep($i) ConsoleWrite("test2 " & $i & " elapsed: " & TimerDiff($hTimer) & @crlf) Next EndFunc Output: Edit: Notice the jump to 30ms'ish values after "test1 16" Spoiler test1 1 elapsed: 14.0045 test1 2 elapsed: 15.9334 test1 3 elapsed: 15.8825 test1 4 elapsed: 15.9606 test1 5 elapsed: 15.9222 test1 6 elapsed: 15.7454 test1 7 elapsed: 15.9472 test1 8 elapsed: 15.9051 test1 9 elapsed: 15.9438 test1 10 elapsed: 15.8013 test1 11 elapsed: 16.1436 test1 12 elapsed: 15.7921 test1 13 elapsed: 16.1874 test1 14 elapsed: 14.3957 test1 15 elapsed: 15.9312 test1 16 elapsed: 15.8585 test1 17 elapsed: 31.1498 test1 18 elapsed: 31.9282 test1 19 elapsed: 31.8788 test1 20 elapsed: 31.3016 test2 1 elapsed: 15.9113 test2 101 elapsed: 108.2961 test2 201 elapsed: 204.484 test2 301 elapsed: 309.7193 test2 401 elapsed: 402.6918 test2 501 elapsed: 510.0467 test2 601 elapsed: 607.129 test2 701 elapsed: 713.1918 test2 801 elapsed: 807.5916 test2 901 elapsed: 905.7356 test2 1001 elapsed: 1014.4096   Edited November 23, 2020 by GokAy
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now