Sign in to follow this  
Followers 0
ziron321

Stop script after 'x' time, whether it finished or not

8 posts in this topic

Hi guys! I have been using AutoIt for quite a while, and so far I have been able to find the answer to all my questions on the forum, but this one...

I need to way to stop a script after 'x' time since it started running, no matter what part of the script it is actually running. I guess I need to set a timer at the beginning but to be sincere I have no clue how to handle it since it would need to be some kind of 'paralell execution'.

Can this be achieved?

Thanks a lot!

George

Share this post


Link to post
Share on other sites



$tStart = _Timer_Init()

then

Do

Until _Timer_Diff($tStart) > X

X is in milliseconds

Good luck :graduated:

Share this post


Link to post
Share on other sites

ziron321,

Welcome to the AutoIt forum. :)

Adlib should be what you need - it allows you "break in" to a running script. Either set the set the Adlib interval to the required delay or check it as you go along like this: ;)

Global $iBegin = TimerInit()

AdlibRegister("_Test", 1000)

While 1
    Sleep(10)
WEnd

Func _Test()
    If TimerDiff($iBegin) > 10 * 1000 Then ; Wait for 10 secs
        ConsoleWrite("Time's up" & @CRLF)
        Exit
    Else
        ConsoleWrite("Still going!" & @CRLF)
    EndIf
EndFunc

All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You can try AdlibRegister : http://www.autoitscript.com/autoit3/docs/functions/AdlibRegister.htm

You can check register a function that would check a timerDiff every second for exemple, and if the timerdiff is higher or equal to the maximum time you want your application to run, then exit :

AdlibRegister("CheckTime", 1000) ;Check every second
Global $Timer = TimerInit()
Global $MaxTime = 10 * 1000 ;10 Seconds

While 1
     ;Looping...
     sleep (10)
WEnd

Func CheckTime()
     If TimerDiff($Timer) >= $MaxTime Then
          ConsoleWrite("Max Time reached... Closing" & @CRLF)
          Exit
     Else
          ConsoleWrite("Not Yet..." & @CRLF)
     EndIf
EndFunc ;==>CheckTime

[EDIT1]

@Melba23 : Lol.. I posted the same example a the same time as you.

[EDIT2]

Put a sleep in the loop :-)

Edited by jmon

Share this post


Link to post
Share on other sites

jmon,

Nice to see we had the same idea - but please put a Sleep in your While...WEnd loop in future or you are going to get a very hot CPU! :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

GREAT!! Thanks a lot! It was easier than I thought! :idiot:

I did it even simpler, I made the function just display an error message and exit, and set the AdLibRegister to 20000 (20 secs), so the function is called once, at 20 secs since execution started. Works like a charm.

Thank you again!

Cheers!

Share this post


Link to post
Share on other sites

ziron321,

I did wonder if that would be enough for you, but it seemed a better idea to give you the more complex solution. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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