Jump to content
Sign in to follow this  
omercraft

hi i made a script and i want it to start over every 4 hours all the script !

Recommended Posts

omercraft

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

Share this post


Link to post
Share on other sites
XaelloNegative

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~ ;)

Share this post


Link to post
Share on other sites
Danp2
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.

Share this post


Link to post
Share on other sites
XaelloNegative
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~ ;)

Share this post


Link to post
Share on other sites
omercraft

how i can use the TimerInit and TimerDiff ?

 

Share this post


Link to post
Share on other sites
Ascer

@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 by Ascer

Share this post


Link to post
Share on other sites
KickStarter15

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

Share this post


Link to post
Share on other sites
Juvigy

You can also use the Task Scheduler to create a task for that.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×