System.Diagnostics.Process.BeginOutputReadLine Method

Begins asynchronous read operations on the redirected Process.StandardOutput stream of the application.

Syntax

[System.Runtime.InteropServices.ComVisible(false)]
public void BeginOutputReadLine ()

Remarks

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

In contrast, Process.BeginOutputReadLine starts asynchronous read operations on the Process.StandardOutput stream. This method enables a 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 Process.StandardOutput for a System.Diagnostics.Process :

[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]

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

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

Note:

You cannot mix asynchronous and synchronous read operations on a redirected stream. Once the redirected stream of a System.Diagnostics.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 Process.BeginOutputReadLine with a call to System.IO.StreamReader.ReadLine on the Process.StandardOutput stream, or vice versa. However, you can read two different streams in different modes. For example, you can call Process.BeginOutputReadLine and then call System.IO.StreamReader.ReadLine for the Process.StandardError stream.

Requirements

Namespace: System.Diagnostics
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0