ziron321 Posted August 22, 2012 Share Posted August 22, 2012 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 Link to comment Share on other sites More sharing options...
RedneckTech Posted August 22, 2012 Share Posted August 22, 2012 $tStart = _Timer_Init() then Do Until _Timer_Diff($tStart) > X X is in milliseconds Good luck Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 22, 2012 Moderators Share Posted August 22, 2012 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 EndFuncAll clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jmon Posted August 22, 2012 Share Posted August 22, 2012 (edited) You can try AdlibRegister : http://www.autoitscript.com/autoit3/docs/functions/AdlibRegister.htmYou 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 August 22, 2012 by jmon [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 22, 2012 Moderators Share Posted August 22, 2012 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! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jmon Posted August 22, 2012 Share Posted August 22, 2012 Thanks, I just thought about that when I saw your example ! [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
ziron321 Posted August 22, 2012 Author Share Posted August 22, 2012 GREAT!! Thanks a lot! It was easier than I thought! 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! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 22, 2012 Moderators Share Posted August 22, 2012 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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