Run this program and notice that, you can close the application just fine if you close it before pressing the "Being Processing Now" button.
Then run it again, and notice that, you cannot close the application after pressing the "Begin Processing Now" button.
Is there a way to fix this?
; Example of problem I'm having with the GUI not closing. ; How do I fix this? #include <GuiEdit.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) $MainForm = GUICreate("Test Application", 600, 400, 200, 200, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_OVERLAPPEDWINDOW,$WS_TILEDWINDOW,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS)) GUISetOnEvent($GUI_EVENT_CLOSE, "MainFormClose") $LogOutputTextBox = GUICtrlCreateEdit("", 8, 8, 580, 280, BitOR($ES_READONLY,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL)) $GoButton = GUICtrlCreateButton("Begin Processing Now !", 8, 300, 237, 33, $WS_GROUP) GUICtrlSetOnEvent($GoButton, "ProcessingLoop") GUISetState(@SW_SHOW) While 1 ; Loop where the main application waits for user input. ; This works... If it reaches this and the user presses the main ; form close button, then the application closes just fine. Sleep (1000) WEnd Func MainFormClose () ; This works fine, unless I'm in the processing loop. ; Why does this not work when I'm in the processing loop? MsgBox (0, "Closing", "You pressed the close button! Yay! Now exiting.") Exit EndFunc Func ProcessingLoop () ; This loop simulates the main application processing loop. ; This is the part that I cannot exit. I'm putting sleeps in ; here like crazy. Why doesn't the Close Button event fire ; when I'm in this loop? For $x = 1 to 30 ; If this were a real application, I would be doing something important here, ; like calculating the Question to the Ultimate Answer. But just for demo ; purposes, I'm going to just output some text. OutputText ("I am doing something. I have done something " & $x & " times now.") OutputText ("Boy I sure wish I could exit this application now.") OutputText ("Unfortunately, I must be task-killed now. WHY?!") Sleep (1000) Next EndFunc Func OutputText ($TextLine) ; Subroutine that makes it easy to output text to the edit control, for demonstration purposes. GuiCtrlSetData( $LogOutputTextBox, GuiCtrlRead ($LogOutputTextBox) & $TextLine & @CRLF) _GUICtrlEdit_LineScroll($LogOutputTextBox, 0, _GUICtrlEdit_GetLineCount($LogOutputTextBox)) EndFunc