littlebigman Posted August 1, 2023 Posted August 1, 2023 Hello, The Cancel button is unresponsive after launching a DOS app with Run(), even while calling GUIGetMsg() within the inner loop: While True $nMsg = GUIGetMsg() Switch $nMsg Case $OK Local $sOutput = Null, $sErrOutput = Null Local $iReturn = Run($LINE, $OUTPUTDIR, @SW_HIDE,$STDOUT_CHILD + $STDERR_CHILD) If @error Then Exit MsgBox($MB_ICONERROR, "Error", "Run failed.") While True ;HERE Cancel still unresponsive $nMsg = GUIGetMsg() if $nMsg = $GUI_EVENT_CLOSE or $nMsg = $Cancel Then ExitLoop $sErrOutput = StderrRead($iReturn) if StringInStr($sErrOutput,"ERROR") then Exit ConsoleWrite("Error reported by app:" & @CRLF & $sErrOutput & @CRLF) if StringInStr($sErrOutput,"WARNING") then ConsoleWrite("Warning reported by app:" & @CRLF & $sErrOutput & @CRLF) $sOutput = StdoutRead($iReturn) If @error Then ExitLoop if StringInStr($sOutput,"ERROR") then Exit ConsoleWrite("Error reported by app:" & @CRLF & $sOutput & @CRLF) _GUICtrlEdit_AppendText($Edit1, StringLeft($sOutput,50) & @CRLF) ; Just grab the first fifty chars Sleep(1000) ;good enough to avoid freezing the GUI? WEnd $sOutput = StdoutRead($iReturn) & @CRLF _GUICtrlEdit_AppendText($Edit1, @CRLF & $sOutput & @CRLF & "Done." & @CRLF) Case $Cancel,$GUI_EVENT_CLOSE Exit EndSwitch WEnd Any idea what I could try to let the user cancel the app? Thank you.
Solution Andreik Posted August 1, 2023 Solution Posted August 1, 2023 Actually the sleep from the inner loop will pretty much make your GUI unresponsive. Since GUIGetMsg() automatically idles the CPU when required you can get rid of that sleep and see if it works.
littlebigman Posted August 1, 2023 Author Posted August 1, 2023 (edited) Good call :-) Thank you. Edited August 1, 2023 by littlebigman
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