0

My console program outputs "*" symbols to indicate progress.
I'd like to read this in order to update the progress bar in a Windows form:

int Progress=0;
System.Diagnostics.Process ProcessObj = new System.Diagnostics.Process();
ProcessObj.StartInfo.UseShellExecute = false;
ProcessObj.StartInfo.CreateNoWindow = true;
ProcessObj.StartInfo.RedirectStandardOutput = true;
ProcessObj.Start();
while(!ProcessObj.HasExited){
   Progress+= ProcessObj.StandardOutput.ReadBlock(buffer, index, 1);
}
Progress+= ProcessObj.StandardOutput.ReadBlock(buffer, index, 1);

Usually, it waits till the process exits before reading anything at all (same for Read), though sometimes it will read the first 1 to 3 characters first.

Anyone know what is causing this?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by DustinS
0

You probably need to use an asynchronous read by calling BeginOutputReadLine and setting an OutputDataReceived event handler.
I have no experience with it, so I can only direct you to the MSDN help.
MSDN Process.BeginOutputReadLine
Maybe someone else can offer some more experienced advice.

0

I've tried ".BeginOutputReadLine()" with new ".OutputDataReceived" event (which only responds after a line-end, unfortunately), and I've tried calling ".StandardOutput.Read()" from a new thread created just after ".Start()" was called.

Both of these processed output asynchronously for my test console program, but waited till the program I'm interested in (which involves usb communication) was complete before responding.

Edited by DustinS: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.