Process.CancelErrorRead Method ()
Cancels the asynchronous read operation on the redirected StandardError stream of an application.
Assembly: System (in System.dll)
After canceling, you can resume the asynchronous read operation by calling BeginErrorReadLine again.
When you call StandardError are completed and then the event handler is disabled. All further redirected output to StandardError is saved in a buffer. If you re-enable the event handler with a call to BeginErrorReadLine, the saved output is sent to the event handler and asynchronous read operations resume. If you want to change the event handler before resuming asynchronous read operations, you must remove the existing event handler before adding the new event handler:, all in-progress read operations for
// At this point the DataReceivedEventHandler(ErrorHandler1) // has executed a CancelErrorRead. // Remove the prior event handler. process.ErrorDataReceived -= new DataReceivedEventHandler(ErrorHandler1); // Register a new event handler. process.ErrorDataReceived += new DataReceivedEventHandler(ErrorHandler2); // Call the corresponding BeginErrorReadLine. process.BeginErrorReadLine();
You cannot mix asynchronous and synchronous read operations on the redirected StandardError stream. Once the redirected stream of a Process is opened in either asynchronous or synchronous mode, all further read operations on that stream must be in the same mode. If you cancel an asynchronous read operation on StandardError and then need to read from the stream again, you must use BeginErrorReadLine to resume asynchronous read operations. Do not follow with a call to the synchronous read methods of StandardError such as Read, ReadLine, or ReadToEnd.
The following example starts the nmake command with user supplied arguments. The error and output streams are read asynchronously; the collected text lines are displayed to the console as well as written to a log file. If the command output exceeds a specified number of lines, the asynchronous read operations are canceled.
for full trust for the immediate caller. This member cannot be used by partially trusted code.
Available since 2.0