TheCrimsonCrusader Posted January 29, 2009 Share Posted January 29, 2009 This is a simple script that displays the current time and has a button named "Run Function" to call a function where it sleeps for 5 seconds. How can I call the function, but still have the current time continuing to update on the main GUI? As expected in its current state, when I run the function, the time on the main GUI stops for 5 seconds and then resumes once the function is complete. I will be adding a progress bar routine that runs within the function later on that will go in place of the "sleep for 5 seconds" place holder, but I was needing to get this little detail figured out first. I don't think I could put the time update loop in the same loop that will be in the function, because it will perform a number of tasks before it ever returns to the top of the loop to update the time. Thanks in advance! CODE#include <GUIConstantsEx.au3> #include <Date.au3> Opt ("GUIOnEventMode", 1) $GUI=GuiCreate("Title",200,100,-1,-1) $Button1 = GUICtrlCreateButton("Run Function", 20, 60) GUICtrlSetOnEvent($BUTTON1, "RunFunction") $CurrentTime = _DateTimeFormat( _NowCalc(),3) $label=GUICtrlCreateLabel($CurrentTime,20,20,140,20) GUICtrlSetFont (-1,10, 800) GUISetOnEvent($GUI_EVENT_CLOSE,"CloseGUI") GUISetState(@SW_SHOW) While 1 If $CurrentTime <> _DateTimeFormat( _NowCalc(),3) Then $CurrentTime = _DateTimeFormat( _NowCalc(),3) GUICtrlSetData($label, $CurrentTime) EndIf WEnd Func RunFunction() Sleep(5000) EndFunc Func CloseGUI() Exit EndFunc Link to comment Share on other sites More sharing options...
Authenticity Posted January 29, 2009 Share Posted January 29, 2009 Well, the problem is that AutoIt is not multithreaded and while your script is sleeping 5 seconds it's suspended so no code get executed at this time interval. Link to comment Share on other sites More sharing options...
SpookMeister Posted January 29, 2009 Share Posted January 29, 2009 I have seen some people embed another script that hides in the background that receives and sends information to and from hidden controls on the main form to address these types of concerns. Haven't played with it much myself though. [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 29, 2009 Moderators Share Posted January 29, 2009 TheCrimsonCrusader,Look at Adlib in the Help file. It lets you call a specific function at defined intervals, pausing your main script while that function runs, but then resuming it once it has terminated.Sounds like just the thing for your timer update.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...
Developers Jos Posted January 29, 2009 Developers Share Posted January 29, 2009 Well, the problem is that AutoIt is not multithreaded and while your script is sleeping 5 seconds it's suspended so no code get executed at this time interval.AdlibEnable() works fine during Sleep() SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
TheCrimsonCrusader Posted January 29, 2009 Author Share Posted January 29, 2009 Thanks, I will give adlib a shot and see what I can come up with. Link to comment Share on other sites More sharing options...
Authenticity Posted January 29, 2009 Share Posted January 29, 2009 Yes it's working. poor me, I should know that it's posted as event and not blocked... Anyway, forgive me about my misleading post. 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