hmsSurprise Posted April 18, 2007 Share Posted April 18, 2007 Was wondering if you know of a method for limiting the amount of time a function is allowed to run? Most of the functions I have in mind are not GUIs so haven't really considered a message loop. I suppose I could compile them and run them standalone and then kill the process if it runs too long. Any other ideas? I have searched the forum and help but haven't found my particular application. Would appreciate the benefit of your experience. Thanks, jh Link to comment Share on other sites More sharing options...
PantZ4 Posted April 18, 2007 Share Posted April 18, 2007 Try look at TimerInit & TimerDiff in the help file. Link to comment Share on other sites More sharing options...
hmsSurprise Posted April 18, 2007 Author Share Posted April 18, 2007 Try look at TimerInit & TimerDiff in the help file.Thanks for posting.Yes that would tell me how long a function had been running if the TimerDiff statement could be executed. I should have stated that I want to terminate a function that has run too long because it is hung, i.e. the timerDiff statement couldn't execute because it is after the hang.jh Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 18, 2007 Share Posted April 18, 2007 (edited) The function could be interrupted by lots of things, like GUI events, hot keys, or AdLibEnable(), but it would return to the function after handling those interrupts. Something inside the called function would have to be monitoring an external flag, like a Global variable, or it could time itself with TimerInit() and TimerDiff(). Example of an external flag: Global $Timeout = 0 Global $Time = TimerInit() AdlibEnable("_TimeCheck", 100) _MyFunc() MsgBox(0, "Test", "Done.") Func _MyFunc() $Pigs_Fly = False Do ; Loop forever If $Timeout Then ExitLoop Until $Pigs_Fly EndFunc Func _TimeCheck() ; Timeout at 30sec If TimerDiff($Time) > 30 * 1000 Then $Timeout = 1 AdlibDisable() EndIf EndFunc Just move the TimerInit()/TimerDiff() stuff inside the loop for the function to timeout itself internally. P.S. Just saw the reply about a hung function. You can't 'kill' the function without exiting the script, but an AdLibEnable() timer like above could do some error processing and exit the script. Edited April 18, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
hmsSurprise Posted April 18, 2007 Author Share Posted April 18, 2007 Thanks, Never would have thought to look for a something by the name AdlibEnable to help with timing out. This can work if I use ( quit being lazy) timeout options on all the WinWait type calls. Think I will take a little time and briefly look at all the functions in the help file. Well maybe more than a little time.... Thanks again, sir. jh 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