Jump to content

Cancel button won't work with Run()


Go to solution Solved by Andreik,

Recommended Posts

Posted

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
Posted

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.

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...