airsea Posted April 12, 2024 Posted April 12, 2024 Hello, I have a loop that checks for an event input from a GUI and acts upon the different events by calling functions. A basic outline is shown below in red. My question is, what happens if a GUI input event occurs while Fxn is running in this case? Does it wait for the completion of the Fxn to complete to check for an event on the next while loop or is this done in parallel? I thought it was the former, but it seems to be the latter based on some testing. To avoid this, I have added a sleep command after the EndSwitch statement that is longer than the duration of the Fxn but I was curious about how this was actually handled. Thanks, Nick While 1 $nMsg = GUIGetMsg() Switch $nMsg() Case xyz Fxn() EndSwitch WEnd Func Fxn()
Solution Nine Posted April 12, 2024 Solution Posted April 12, 2024 (edited) 11 minutes ago, airsea said: Does it wait for the completion of the Fxn to complete to check for an event Yes, even on event mode, it will wait till the fxn is completed... #include <GUIConstants.au3> Opt("GUIOnEventMode", True) Local $hGUI = GUICreate("Example") GUISetOnEvent($GUI_EVENT_CLOSE, Terminate) Local $idB1 = GUICtrlCreateButton("B1", 20, 20, 100, 25) GUICtrlSetOnEvent(-1, B1) Local $idB2 = GUICtrlCreateButton("B2", 20, 120, 100, 25) GUICtrlSetOnEvent(-1, B2) GUISetState() Local $iCount = 0 While Sleep(150) $iCount += 1 If Not Mod($iCount, 5) Then ConsoleWrite("Main " & $iCount & @CRLF) WEnd Func Terminate() Exit EndFunc Func B1() For $i = 1 To 20 ConsoleWrite("B1 " & $i & @CRLF) Sleep(150) Next EndFunc Func B2() ConsoleWrite("B2" & @CRLF) EndFunc When you post code, even if it is very small, use the method shown in the link. Thanks. Edited April 12, 2024 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
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