Process.BeginOutputReadLine Method ()
Begins asynchronous read operations on the redirected StandardOutput stream of the application.
Assembly: System (in System.dll)
The StandardOutput stream can be read synchronously or asynchronously. Methods such as Read, ReadLine, and ReadToEnd perform synchronous read operations on the output stream of the process. These synchronous read operations do not complete until the associated Process writes to its StandardOutput stream, or closes the stream.
In contrast, 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.starts asynchronous read operations on the
Set UseShellExecute to false.
Set RedirectStandardOutput to true.
Start the Process.
You can cancel an asynchronous read operation by calling CancelOutputRead. The read operation can be canceled by the caller or by the event handler. After canceling, you can call 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 with a call to ReadLine on the StandardOutput stream, or vice versa. However, you can read two different streams in different modes. For example, you can call and then call ReadLine for the StandardError stream.
The following example illustrates how to perform asynchronous read operations on the redirected StandardOutput stream of the sort command. The sort command is a console application that reads and sorts text input.
The example creates an event delegate for the SortOutputHandler event handler and associates it with the OutputDataReceived event. The event handler receives text lines from the redirected StandardOutput stream, formats the text, and writes the text to the screen.
for full trust for the immediate caller. This member cannot be used by partially trusted code.
Available since 2.0