System.Diagnostics.DataReceivedEventHandler Delegate

Represents the method that will handle the Process.OutputDataReceived event or Process.ErrorDataReceived event of a System.Diagnostics.Process.


public delegate void DataReceivedEventHandler (object sender, DataReceivedEventArgs e)


Documentation for this section has not yet been entered.
Documentation for this section has not yet been entered.


When you create a System.Diagnostics.DataReceivedEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event-handler delegates, see Events and Delegates.

To asynchronously collect the redirected Process.StandardOutput or Process.StandardError stream output of a process, add your event handler to the Process.OutputDataReceived or Process.ErrorDataReceived event. These events are raised each time the process writes a line to the corresponding redirected stream. When the redirected stream is closed, a null line is sent to the event handler. Ensure that your event handler checks for this condition before accessing the DataReceivedEventArgs.Data property. For example, you can use the static method string.IsNullOrEmpty(string) to validate the DataReceivedEventArgs.Data property in your event handler.


Namespace: System.Diagnostics
Assembly: System (in System.dll)
Assembly Versions:,
Since: .NET 2.0