Jump to content

Recommended Posts

Posted

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
Posted (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 by Nine

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
×
×
  • Create New...