Ensure Standard outpurt/error have been handled before Process.CancelOutputRead
-
Monday, July 30, 2012 9:52 AM
I am initializing a Process object as shown below. As you can see I am calling to CancelOutputRead as soon as the process finishes its work. But I am not sure by this time the standard output and error have been logged or not. Is there any means to know this before cancelling the asynchronous reading of the output.
Process m_cvsProcess=new Process();
m_cvsProcess.StartInfo.UseShellExecute = false;
m_cvsProcess.StartInfo.RedirectStandardOutput = true;
m_cvsProcess.StartInfo.RedirectStandardError = true;
m_cvsProcess.EnableRaisingEvents = true;
m_cvsProcess.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);
m_cvsProcess.ErrorDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);
m_cvsProcess.Exited += new EventHandler(cvsProcess_Exited);
m_cvsProcess.Start();
m_cvsProcess.BeginOutputReadLine();
m_cvsProcess.BeginErrorReadLine();bool exited=false;
while (!exited )
{
exited = executorProcess.WaitForExit(60000);
}try
{
exited.CancelOutputRead();
}
void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if(!String.IsNullOrEmpty(e.Data))
{
AddLog(e.Data); // write output to RichTextBox
}
}
All Replies
-
Monday, July 30, 2012 12:39 PM
exited.CancelOutputRead();
??? exited is a bool. You're not compiling this code.
-
Monday, July 30, 2012 4:15 PMI have m_cvsProcess.CancelOutputRead(); in my code. That was a type mistake.
-
Tuesday, July 31, 2012 12:57 PMModerator
Hi Qasker,
Welcome to the MSDN Forum.
You can know it in process_OutputDataReceived function. When data is received, this function will be run. And you can check the log is been logged successfully or not in the AddLog function. You can feedback the status in the AddLog function.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked As Answer by Mike FengMicrosoft Contingent Staff, Moderator Thursday, August 09, 2012 3:12 PM

