Hi,
I have a GUI application that executes (in a new process) "console" applications and parse the output. To redirect the Output i set the pConsole.StartInfo.RedirectStandardOutput to true. I also subscribes to the event pConsole.Exited.
The problem I see is that I have to use Thread.Sleep() in the Exited event handler to get the last 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 executes before my last pConsole_DataAvailableEvent. Anyone knows how/why this is happening?
I also use a mutex/lock to make sure my Exited event is finished before I start execute my next console application.