kim1234 Posted June 8, 2015 Posted June 8, 2015 (edited) Hi guys, I'm trying to understand the event handler. It seems like if there is a sleep/loop at the base level (i.e. not inside a function) then the event handler triggers, but a sleep/loop in a function stops the event handler triggering. How does AutoIt handle this sort of thing. Here's my test code, it creates two buttons both with event handlers. Once the 'test' function is invoked, the time event doesn't trigger. If the test function is not invoked then the time function does trigger. What's the logic behind that?#include <guiconstants.au3> Opt("GuiOnEventMode", True) GUICreate("Test GUI", 200, 100, 100, 100) $mGUI_ButtonTime = GUICtrlCreateButton("Time", 30, 10, 50, 26) GUICtrlSetOnEvent($mGUI_ButtonTime, "TimeFunction") $mGUI_ButtonTest = GUICtrlCreateButton("Test", 30, 50, 50, 26) GUICtrlSetOnEvent($mGUI_ButtonTest, "TestFunction") GUISetState(@SW_SHOW) While 1 Sleep(100) ; events work while sleeping at this level WEnd Func TimeFunction() ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & ": Time" & @CRLF) EndFunc Func TestFunction() ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & ": Test" & @CRLF) While 1 Sleep(100) ; events DON'T work while sleeping at this level WEnd EndFunc Edited June 8, 2015 by Melba23 Added code tags
Moderators Melba23 Posted June 8, 2015 Moderators Posted June 8, 2015 kim1234,Welcome to the AutoIt forums.Correct, AutoIt will not run another function if it is still occupied within an earlier call. I recommend reading the Interrupting a running function tutorial in the Wiki to get more information about this. The obvious solution is to return t the main script rather then remain within a function - but the tutorial does show how you can work around this.And when you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags.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
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