我想从应用程序重定向 c# 中富文本框上的进程输出。但问题是进程的输出在很长一段时间后才显示,直到进程完成其工作。
这是我的代码-
StringBuilder outputBuilder = new StringBuilder();
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.CreateNoWindow = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.UseShellExecute = false;
//processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processStartInfo.WorkingDirectory = strHMIModelAppFolder;
processStartInfo.FileName = ConfigurationHandlerInstance.GetHMIModelApplication();
Process process = new Process();
process.StartInfo = processStartInfo;
process.EnableRaisingEvents = true;
process.OutputDataReceived += new DataReceivedEventHandler
(
delegate(object objSender, DataReceivedEventArgs eventArgs)
{
outputBuilder.Append(eventArgs.Data);
outputBuilder.Append(Environment.NewLine);
this.SetText(outputBuilder.ToString());
}
);
process.Exited += new EventHandler(ProcExited);
process.Start();
process.BeginOutputReadLine();
//process.WaitForExit();
//while (!process.HasExited)
//{
// Application.DoEvents();
//}
// use the output
string output = outputBuilder.ToString();
this.SetText(output);