I have a GUI application that runs (in a new process) console applications and parses the output. To redirect the output, I set pConsole.StartInfo.RedirectStandardOutput to true. I also subscribe to the pConsole.Exited event.
The problem that I see is that I have to use Thread.Sleep () in the Exited event handler to get the latest data.
My Exited event handler looks like this:
Thread.Sleep(100); // Wait for additional data (if any). pConsole.OutputDataReceived -= new System.Diagnostics.DataReceivedEventHandler(this.localTerminal_DataAvailableEvent); int exit = pConsole.ExitCode; pConsole.Dispose(); pConsole = null;
It seems that the Exited event is fired before my last pConsole_DataAvailableEvent. Does anyone know how / why this happens?
I also use mutex / lock to complete my Exited event before I launch the next console application.
c # process console
Anders r
source share