jvanegmond 303 Posted July 31, 2015 A large part in automation is timing related. You want to wait for a window to appear. For a control to become enabled. You don't want your script to hang so you specify some timeout with a generic failure behavior. AutoIt solves that with special methods: WinWait, WinWaitClose, WinWaitActive, WinWaitNotActive. You can use those or you implement your custom solution which way too quickly becomes verbose (example in spoiler tags below).Without crippling the question by including an answer: How can we do this better? Const $TIMEOUT_MS = 5000 Const $CHECKWAIT_MS = 100 ; Waiting for something to be true with a timeout and error handler $start = TimerInit() Local $success = False While TimerDiff($start) < $TIMEOUT_MS $success = MyCondition() If $success Then ExitLoop Sleep($CHECKWAIT_MS) WEnd If Not $success Then MyErrorHandler() EndIf Func MyCondition() Static $n = 0 $n += 1 If $n == 10 Then Return True Else Return False EndIf EndFunc Func MyErrorHandler() ConsoleWriteError("Something happened" & @CRLF) Exit 1 EndFunc Hide jvanegmond's signature Hide all signatures github.com/jvanegmond Share this post Link to post Share on other sites
JohnOne 1,598 Posted July 31, 2015 I generally do mine a little different, similar too the following usually.Const $TIMEOUT_MS = 5000 Const $CHECKWAIT_MS = 100 ; Waiting for something to be true with a timeout and error handler $start = TimerInit() Local $success = False While 3 If MyCondition() Then ExitLoop EndIf If TimerDiff($start) >= $TIMEOUT_MS Then MyErrorHandler() EndIf Sleep($CHECKWAIT_MS) WEnd Func MyCondition() Static $n = 0 $n += 1 If $n == 10 Then Return True Else Return False EndIf EndFunc ;==>MyCondition Func MyErrorHandler() ConsoleWrite("Something happened" & @CRLF) Exit 1 EndFunc ;==>MyErrorHandler Hide JohnOne's signature Hide all signatures AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Share this post Link to post Share on other sites