b3lorixx Posted January 27, 2011 Share Posted January 27, 2011 (edited) Basically i want to run a function every 5 minutes without the use of a while or sleep currently i am tryin to use this: Local $Timer = iniread("wrdtc-settings.ini", "Timer", "current", "0") func Getinfo() $current = TimerInit() $NewCur = $Timer + 500000 If $NewCur > $current Then IniWrite ("wrdtc-settings.ini", "Timer", "current", $current) EndIf EndFunc but its not working and i cant figure out what else to do.. Edited January 27, 2011 by b3lorixx Link to comment Share on other sites More sharing options...
Varian Posted January 27, 2011 Share Posted January 27, 2011 I assume that there is an AdLibRegister() function that is calling GetInfo(), or GetInfo() is being called from somewhere in another While loop. The problem is that each time it is called, the $Current value is reset by TimerInit() and it will always be smaller than $NewCur, even if $Timer is 0 (the value of $NewCur will be at a minimum of 10000, and it will only take milliseconds to go through the function lines, and since $Current is always less than $NewCur, that millisecond time will be written to the INI file) If you want to accomplish this without a formal While Loop, you will thry something like this: Global $Current = TimerInit() ;must be declared BEFORE calling the function for the first time AdLibRegister("Getinfo") ;Your script, which must in someway never end, either with a while or its' natural progress Func Getinfo() If TimerDiff($Current) < 300000 Then Return ;Skip this time and go back to main script ;Otherwise, do your stuff here ;If you need to return something from the function, do this: ;$Current = TimerInit() ;reset the timer since the function has run this time ;Return ;whatever you need to return ;If you do not need to return anything from the function, do this: Return $Current = TimerInit() ;reset the timer since the function has run this time EndFunc ;==>Getinfo Link to comment Share on other sites More sharing options...
JoHanatCent Posted January 27, 2011 Share Posted January 27, 2011 AdlibRegister("Getinfo", 5 * 60 * 1000); Run every 5 mimutes $StopHour = @HOUR + 1; The Hour now plus one our when you want to end the loop! Do;To keep something going until you want to end it Until @HOUR = $StopHour Func Getinfo() MsgBox(0, '', 'It is time to do something!', .5) EndFunc ;==>GetinfoBasically i want to run a function every 5 minutes without the use of a while or sleepBasically you can not repeat a task if you do not have some sort of loop. This working example does not use any file to read anything but wil run every 5 minutes. It wil stop the loop after an hour. Link to comment Share on other sites More sharing options...
b3lorixx Posted January 27, 2011 Author Share Posted January 27, 2011 I assume that there is an AdLibRegister() function that is calling GetInfo(), or GetInfo() is being called from somewhere in another While loop. The problem is that each time it is called, the $Current value is reset by TimerInit() and it will always be smaller than $NewCur, even if $Timer is 0 (the value of $NewCur will be at a minimum of 10000, and it will only take milliseconds to go through the function lines, and since $Current is always less than $NewCur, that millisecond time will be written to the INI file) If you want to accomplish this without a formal While Loop, you will thry something like this: Global $Current = TimerInit() ;must be declared BEFORE calling the function for the first time AdLibRegister("Getinfo") ;Your script, which must in someway never end, either with a while or its' natural progress Func Getinfo() If TimerDiff($Current) < 300000 Then Return ;Skip this time and go back to main script ;Otherwise, do your stuff here ;If you need to return something from the function, do this: ;$Current = TimerInit() ;reset the timer since the function has run this time ;Return ;whatever you need to return ;If you do not need to return anything from the function, do this: Return $Current = TimerInit() ;reset the timer since the function has run this time EndFunc ;==>Getinfo yes but $Timer isnt 0, its set to be the current time after you run the configuration form that MUST be run. So i was using $NewCur = $Timer + 500000 to add 5 minutes to $timer to make sure the function wasnt running until it was 5 minutes past the last run Link to comment Share on other sites More sharing options...
b3lorixx Posted January 27, 2011 Author Share Posted January 27, 2011 AdlibRegister("Getinfo", 5 * 60 * 1000); Run every 5 mimutes $StopHour = @HOUR + 1; The Hour now plus one our when you want to end the loop! Do;To keep something going until you want to end it Until @HOUR = $StopHour Func Getinfo() MsgBox(0, '', 'It is time to do something!', .5) EndFunc ;==>Getinfo Basically you can not repeat a task if you do not have some sort of loop. This working example does not use any file to read anything but wil run every 5 minutes. It wil stop the loop after an hour. yes, but i cant delay my While loop for long because im using it to keep a connection alive Link to comment Share on other sites More sharing options...
wakillon Posted January 27, 2011 Share Posted January 27, 2011 (edited) yes, but i cant delay my While loop for long because im using it to keep a connection alive The easy way ! #include <Date.au3> $_InitTime = _NowCalc ( ) While 1 ; your script Loop $_DateCalc = _DateDiff ( 'n', $_InitTime, _NowCalc ( ) ) If $_DateCalc >= 5 Then MsgBox ( 4096, "", "5 Minutes elapsed ! " & $_DateCalc ) $_InitTime = _NowCalc ( ) EndIf WEnd Edited January 28, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Varian Posted January 27, 2011 Share Posted January 27, 2011 yes but $Timer isnt 0, its set to be the current time after you run the configuration form that MUST be run. So i was using $NewCur = $Timer + 500000 to add 5 minutes to $timer to make sure the function wasnt running until it was 5 minutes past the last runTimerInit() returns an Epoch timestamp. The timestamp for "Thu, 27 Jan 2011 08:40:40 GMT" (3:40 AM EST) is 1296117640If you are increasing $Timer by 50000 each time the function is called, it will take 1296117640 / 50000 or 2592.23528 calls for $timer to eqaul that timestamp. Actually it will take more because you compare $Timer to the current timestamp (which also increases)yes, but i cant delay my While loop for long because im using it to keep a connection aliveIn the event that you do get the timer correct, what kind of function can you run within the script that will not upset your super-sensitive existing While loop? Why not just do the TimerInit() at the beginning of the script, make a function that checks if it has been 5 minutes ( with TimerDiff() ), and if so, (1)start an external script and (2) reset the timer?The easy way ! The OP requires that no extra While loops be usedWhat is the point of using TimerInit() if you never call TimerDiff()? Link to comment Share on other sites More sharing options...
wakillon Posted January 27, 2011 Share Posted January 27, 2011 The OP requires that no extra While loops be usedWhat is the point of using TimerInit() if you never call TimerDiff()?His last post : yes, but i cant delay my While loop for long because im using it to keep a connection aliveI place it in his Own while loop and don't use any TimerInit()... AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
b3lorixx Posted January 27, 2011 Author Share Posted January 27, 2011 His last post : yes, but i cant delay my While loop for long because im using it to keep a connection aliveI place it in his Own while loop and don't use any TimerInit()...I figured it out after a few hours of trial and error. i did try to put the entire code into the while loop. but it was bugging and just constantly spammed lol Link to comment Share on other sites More sharing options...
wakillon Posted January 28, 2011 Share Posted January 28, 2011 I figured it out after a few hours of trial and error. i did try to put the entire code into the while loop. but it was bugging and just constantly spammed lolYou want more help, I need entire code... AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts 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