jvanegmond Posted July 31, 2015 Share 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 github.com/jvanegmond Link to comment Share on other sites More sharing options...
JohnOne Posted July 31, 2015 Share 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 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. 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