Jump to content
Sign in to follow this  
TheCrimsonCrusader

Current Time and Function Call

Recommended Posts

TheCrimsonCrusader

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

Share this post


Link to post
Share on other sites
Authenticity

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.

Share this post


Link to post
Share on other sites
SpookMeister

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]

Share this post


Link to post
Share on other sites
Melba23

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._______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
Jos

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
TheCrimsonCrusader

Thanks, I will give adlib a shot and see what I can come up with.

Share this post


Link to post
Share on other sites
Authenticity

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.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.