C# Process <instance>.StandardOutput InvalidOperationException "Cannot mix synchronous and asynchronous operation on process stream."
I tried this
myProcess = new Process();
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.StartInfo.FileName = "Hello.exe";
myProcess.StartInfo.Arguments ="-say Hello";
myProcess.StartInfo.UseShellExecute = false;
myProcess.OutputDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived);
myProcess.Er开发者_如何学编程rorDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived);
myProcess.Exited += new EventHandler(myProcess_Exited);
myProcess.EnableRaisingEvents = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.ErrorDialog = true;
myProcess.StartInfo.WorkingDirectory = "D:\\Program Files\\Hello";
myProcess.Start();
myProcess.BeginOutputReadLine();
myProcess.BeginErrorReadLine();
Then I am getting this error.. alt text http://img188.imageshack.us/img188/3759/errorstack.jpg
My process takes very long to complete, so I need to show progress in runtime.
You don't need to call ReadLine()
, the line of text that was read is one of the properties passed to you in the DataReceivedEventArgs
object.
精彩评论