DataReceivedEventHandler Delegate

 

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

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

type DataReceivedEventHandler = 
    delegate of 
        sender:Object *
        e:DataReceivedEventArgs -> unit

Parameters

sender
Type: System.Object

The source of the event.

e
Type: System.Diagnostics.DataReceivedEventArgs

A DataReceivedEventArgs that contains the event data.

When you create a 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 Handling and Raising Events.

To asynchronously collect the redirected StandardOutput or StandardError stream output of a process, add your event handler to the OutputDataReceived or 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 Data property. For example, you can use the static method String.IsNullOrEmpty to validate the Data property in your event handler.

The following code 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 a DataReceivedEventHandler delegate for the SortOutputHandler event handler and associates the delegate 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.

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

.NET Framework
Available since 2.0
Return to top
Show: