OutputDataReceived from Process Waits until the end

  • Thread starter Thread starter njbraun
  • Start date Start date
N

njbraun

Guest
All,

I've got an exe that I'm trying to run silently from within my application. If I execute the binary in a command prompt (outside of my app), it spits out about 50 different lines as it is pushing some data over a serial connection before it finally exits.

See the following code to see how I have it setup:


public static void DoTheButton()
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(
@"STMFlashLoader.exe", "-c --pn 8 --br 115200 -i STM32F10xxBxx -e --all -d --fn Sniper.s19");
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.ErrorDialog = false;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = psi;

proc.Start();
proc.BeginOutputReadLine();

proc.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(proc_OutputDataReceived);
}

static void proc_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
}


I would expect that "proc_OutputDataReceived" gets called for each line that I normally see gets written out to the standard out when executing this binary from the command prompt.

Instead, when I kick off this method, I get nothing in console for about 10 seconds, then every one of those 50 lines comes through all at once, rapid fire at the end.

It's like the OutputDataReceived doesn't actually get fired when the output lines are being generated, but only when the entire process finishes, then it gets called 50 times in row.

Anybody have any experience with this?

I'd like to actually use OutputDataReceived to increment a progress bar for the background process.

Continue reading...
 
Back
Top