anixon Posted June 14, 2008 Posted June 14, 2008 (edited) I have written this code to perform a process every hour it does not have to be exactly at the same time every hour for example 01:06ss and then 02:06ss etc rather any time each hour. My question is there a more efficient code method to perform the same process?CODE#include <Date.au3> ; Date Time processing $HourCounter = 00 While 1 If @Hour = 00 Then $HourCounter = 00 EndIf If @Hour <> $HourCounter Then DoSomething() endif If @Hour - $HourCounter <> 0 Then $HourCounter = @HOUR EndIf Sleep(5000) WEnd Func DoSomething() Msgbox(0,"","Hourly Processor") EndFunc Ant.. Edited June 14, 2008 by anixon
monoceres Posted June 14, 2008 Posted June 14, 2008 Some ways: Dim $oldhour while 1 If @HOUR<>$oldhour Then _DoSomething() $oldhour=@HOUR EndIf Sleep(1000) WEnd Func _DoSomething() ;blabla EndFunc AdlibEnable("_DoSomething",3600*1000) while Sleep(1000) WEnd Func _DoSomething() ;blabla EndFunc $timer = TimerInit() While 1 If TimerDiff($timer) >= 3600 * 1000 Then _DoSomething() $timer = TimerInit() EndIf Sleep(1000) WEnd Func _DoSomething() ;blabla EndFunc ;==>_DoSomething Broken link? PM me and I'll send you the file!
anixon Posted June 14, 2008 Author Posted June 14, 2008 Some ways: Dim $oldhour while 1 If @HOUR<>$oldhour Then _DoSomething() $oldhour=@HOUR EndIf Sleep(1000) WEnd Func _DoSomething() ;blabla EndFunc AdlibEnable("_DoSomething",3600*1000) while Sleep(1000) WEnd Thanks for that just love coding because there is always more than one way to do the same thing. Your offerings are more elegant than mine... Ant Func _DoSomething() ;blabla EndFunc $timer = TimerInit() While 1 If TimerDiff($timer) >= 3600 * 1000 Then _DoSomething() $timer = TimerInit() EndIf Sleep(1000) WEnd Func _DoSomething() ;blabla EndFunc ;==>_DoSomething
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