Sometimes, an unexpected popup will cause a line in the script to keep looping until it is noticed and manually fixed to allow it to continue.
Is there a function to detect how long a loop has ran and notify if it has ran for over x minutes?
Thanks!
Is there a function to detect how long a loop has been running?
-
- Posts: 5
- Joined: 14 Jan 2018, 07:08
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: Is there a function to detect how long a loop has been running?
Not unless you make one. But it sounds like your problem could be fixed if given a different approach. Instead of a loop, try using SetTimer and do your check as the first thing in the sub/label. Give it a second check to keep track of how many times that check was successful, then return. If the check fails and it continues, you can reset the counter. Here's an example:
Code: Select all
checkCnt:=0
setTimer,checkThing,100
return
checkThing:
if(!winActive("ExampleWindow")){
checkCnt++
if(checkCnt > 100){ ; if the if-block has be ran 100 times (100ms between each time, so 10000ms/10s)
; do something to fix it, like close the popup
}
return
}
checkCnt:=0
; do normal thing
return
-
- Posts: 5
- Joined: 14 Jan 2018, 07:08
Re: Is there a function to detect how long a loop has been running?
Thanks! I'll give it a try!
Re: Is there a function to detect how long a loop has been running?
Code: Select all
x := (A_ScreenWidth // 2) - 30
y := (A_ScreenHeight // 2) + 80
initialTimestamp := A_TickCount
Loop, 25 {
ToolTip, % "Looping: " . A_Index, % x, % y
Sleep, 50
}
MsgBox, % howLongHasItBeen(initialTimestamp)
howLongHasItBeen(initialTimestamp) {
return (A_TickCount - initialTimestamp)
}
Code: Select all
x := (A_ScreenWidth // 2) - 30
y := (A_ScreenHeight // 2) + 80
DllCall("QueryPerformanceFrequency", "Int64*", frequency)
DllCall("QueryPerformanceCounter", "Int64*", initialTimestamp)
Loop, 25 {
ToolTip, % "Looping: " . A_Index, % x, % y
Sleep, 50
}
MsgBox, % howLongHasItBeen(initialTimestamp, frequency)
howLongHasItBeen(initialTimestamp, frequency) {
DllCall("QueryPerformanceCounter", "Int64*", currentTimestamp)
duration := (currentTimestamp - initialTimestamp) * 1000 ; ms
duration /= frequency
return duration
}
Who is online
Users browsing this forum: Aqualest, jdfnnl, serenite, yanjujino1 and 318 guests