Jump to content

Recommended Posts

Posted

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! 

  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted
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...

Posted (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 by GokAy

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...