Jump to content

Recommended Posts

Posted

I need to know how to give a script some kind of running time limit. So if script hangs and runs more than 30 minutes, it would end itself. Is it possible?

_Timer_SetTimer perhaps? :)

Posted

I need to know how to give a script some kind of running time limit. So if script hangs and runs more than 30 minutes, it would end itself. Is it possible?

_Timer_SetTimer perhaps? :)

TimerInit ( ) and TimerDiff ( ).
  • Moderators
Posted

I need to know how to give a script some kind of running time limit. So if script hangs and runs more than 30 minutes, it would end itself. Is it possible?

_Timer_SetTimer perhaps? :)

Quick and dirty if you're not already using AdlibEnable():
Global $i_kill_mins = 30
AdlibEnable("_KillMeTimeIsUp", $i_kill_mins*60*1000)
While 1
    Sleep(1000000)
WEnd
Func _KillMeTimeIsUp()
    MsgBox(16, "Error", "You ran too damn long!", 1)
    Exit
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted (edited)

This script should exit after 15 sec.

Global $TIME_INIT = TimerInit()
$EXIT_TIME = 15

AdlibEnable("CheckExit",1000)
$GUI = GUICreate("EXAMPLE",300,300)
GUISetState(@SW_SHOW)

While 1
    $MSG = GUIGetMsg()
    If $MSG = -3 Then Exit
    Sleep(20)
WEnd

Func CheckExit()
    If TimerDiff($TIME_INIT)/1000 >= $EXIT_TIME Then 
        AdlibDisable()
        Exit
    EndIf
EndFunc
Edited by Andreik
Posted

Quick and dirty if you're not already using AdlibEnable():

Global $i_kill_mins = 30
AdlibEnable("_KillMeTimeIsUp", $i_kill_mins*60*1000)
While 1
    Sleep(1000000)
WEnd
Func _KillMeTimeIsUp()
    MsgBox(16, "Error", "You ran too damn long!", 1)
    Exit
EndFunc
Thanks for the help! Exactly what I needed.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...