Jump to content

Recommended Posts

Posted (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 by Melba23
Added code tags
  • Moderators
Posted

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

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...