Sign in to follow this  
Followers 0
skysel

How to make script terminate itself?

5 posts in this topic

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? :)

Share this post


Link to post
Share on other sites



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 ( ).

When the words fail... music speaks

Share this post


Link to post
Share on other sites

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

[center]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.[/center]

Share this post


Link to post
Share on other sites

#4 ·  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

When the words fail... music speaks

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0