omercraft Posted February 16, 2018 Share Posted February 16, 2018 hi i made a script and i want it to start over every 4 hours how can i do this ? (all the script) thanks omer Link to comment Share on other sites More sharing options...
XaelloNegative Posted February 16, 2018 Share Posted February 16, 2018 You can add the whole script in a loop then add a sleep at the end like: while 1 ~your script here Sleep(14400000) //4 hours in milliseconds Wend ~XN~ Link to comment Share on other sites More sharing options...
Danp2 Posted February 16, 2018 Share Posted February 16, 2018 9 minutes ago, XaelloNegative said: Sleep(14400000) That's likely not a good solution because the script is essentially "hung" at that statement for the four hour duration. A better option would be to use TimerInit and TimerDiff. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
XaelloNegative Posted February 16, 2018 Share Posted February 16, 2018 1 minute ago, Danp2 said: TimerInit and TimerDiff can also be done like that. On the other hand, as per experience in the office, i don't usually shutdown my PC for a couple of days and the script i have running usually runs for a couple days as well. In any case. Thanks for the added info. ~XN~ ~XN~ Link to comment Share on other sites More sharing options...
omercraft Posted February 17, 2018 Author Share Posted February 17, 2018 how i can use the TimerInit and TimerDiff ? Link to comment Share on other sites More sharing options...
Ascer Posted February 17, 2018 Share Posted February 17, 2018 (edited) @omercraft You can use _Timers.au3 to control actions without freezing Main script. #include <Timers.au3> Local $hGui = GUICreate("Test") Local $iDelay = 5000 ; run script after 5s Local $fEnabled = False ConsoleWrite("Script will now wait " & $iDelay & "ms until enable Module." & @CRLF) Func Example($1, $2, $3, $4) $fEnabled = True EndFunc HotKeySet("{esc}", "ExitProgram") _Timer_SetTimer($hGui, $iDelay, "Example") Func ExitProgram() Exit EndFunc While 1 Sleep(100) If $fEnabled Then ConsoleWrite("Function running now." & @CRLF) WEnd Or even simple example Local $iDelay = 5000 Local $iStartTime = TimerInit() ConsoleWrite("Script will now wait " & $iDelay & "ms until enable Module." & @CRLF) While 1 Sleep(100) If TimerDiff($iStartTime) > $iDelay Then ConsoleWrite("Script is running now." & @CRLF) WEnd Edited February 17, 2018 by Ascer Link to comment Share on other sites More sharing options...
KickStarter15 Posted February 17, 2018 Share Posted February 17, 2018 @omercraft, There are samples given in help file where you can check what you need to know, everything was stated there on how to use TimerInit() and TimerDiff(). Also, show us what have you've got so far for us to help more... Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Juvigy Posted February 19, 2018 Share Posted February 19, 2018 You can also use the Task Scheduler to create a task for that. Link to comment Share on other sites More sharing options...
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