I have a C# form that has a text box that needs to constantly update with the output from an exe while the exe is still running. I know how to update it after the exe has finished but its the constant updating that i need.
You have your process which starts the exe:
// Normal creation and initialization of process - additionally:
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += ProcessOnOutputDataReceived;
process.Start();
process.BeginOutputReadLine();
and the handler:
private void ProcessOnOutputDataReceived( object sender, DataReceivedEventArgs args )
{
// use args.Data
}
EDIT:
I forgot process.StartInfo.UseShellExecute = false;
:/
EDIT:
It turned out, that the exe did not flush the output (see comments)
One way to do this would be to use remoting - in other words, you would poll a well known method in the running executable to retrieve the value and update the value in your textbox based on this. Google .net remoting for some samples.
Alternatively (if you're using .NET3 and on), you could use WCF and something like Tcp or Peer 2 Peer bindings. Without knowing more about your architecture, there's not much more I could say on this.
When you say exe are you talking about running a console application by using process start?
If so then you have to get the output of the console app, see this question.
This is sending input there is an example to read output.
The other option is to have the calling class hook up to an event from your windows form. It will call the event will will cause the form to update the text box.