Process.BeginErrorReadLine Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Begins asynchronous read operations on the redirected StandardError stream of the application.

Namespace:   System.Diagnostics
Assembly:  System (in System.dll)

member BeginErrorReadLine : unit -> unit

Exception Condition

The ProcessStartInfo.RedirectStandardError property is false.

- or -

An asynchronous read operation is already in progress on the StandardError stream.

- or -

The StandardError stream has been used by a synchronous read operation.

The StandardError stream can be read synchronously or asynchronously. Methods such as Read, ReadLine, and ReadToEnd perform synchronous read operations on the error output stream of the process. These synchronous read operations do not complete until the associated Process writes to its StandardError stream, or closes the stream.

In contrast, BeginErrorReadLine starts asynchronous read operations on the StandardError stream. This method enables the designated event handler for the stream output and immediately returns to the caller, which can perform other work while the stream output is directed to the event handler.

Follow these steps to perform asynchronous read operations on StandardError for a Process :

  1. Set UseShellExecute to false.

  2. Set RedirectStandardError to true.

  3. Add your event handler to the ErrorDataReceived event. The event handler must match the System.Diagnostics.DataReceivedEventHandler delegate signature.

  4. Start the Process.

  5. Call BeginErrorReadLine for the Process. This call starts asynchronous read operations on StandardError.

When asynchronous read operations start, the event handler is called each time the associated Process writes a line of text to its StandardError stream.

You can cancel an asynchronous read operation by calling CancelErrorRead. The read operation can be canceled by the caller or by the event handler. After canceling, you can call BeginErrorReadLine again to resume asynchronous read operations.


You cannot mix asynchronous and synchronous read operations on a redirected 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. For example, do not follow BeginErrorReadLine with a call to ReadLine on the StandardError stream, or vice versa. However, you can read two different streams in different modes. For example, you can call BeginErrorReadLine and then call ReadLine for the StandardOutput stream.

The following example uses the net view command to list the available network resources on a remote computer. The user supplies the target computer name as a command-line argument. The user can also supply a file name for error output. The example collects the output of the net command, waits for the process to finish, and then writes the output results to the console. If the user supplies the optional error file, the example writes errors to the file.

No code example is currently available or this language may not be supported.


for full trust for the immediate caller. This member cannot be used by partially trusted code.

.NET Framework
Available since 2.0
Return to top