C # Process <instancep> .StandardOutput InvalidOperationException "Unable to use synchronous and asynchronous work in process flow."

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.ErrorDataReceived += 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 get this error. alt text http://img188.imageshack.us/img188/3759/errorstack.jpg

My process is taking a very long time, so I need to show progress at runtime.

+2


source share


1 answer


You don't need to call ReadLine()

, the line of text that was read is one of the properties passed to you in the object DataReceivedEventArgs

.



+3


source







All Articles