Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Delegado DataReceivedEventHandler

 

Publicado: octubre de 2016

Representa el método que controlará los eventos OutputDataReceived o ErrorDataReceived de un Process.

Espacio de nombres:   System.Diagnostics
Ensamblado:  System (en System.dll)

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

Parámetros

sender
Type: System.Object

Origen del evento.

e
Type: System.Diagnostics.DataReceivedEventArgs

Objeto DataReceivedEventArgs que contiene los datos del evento.

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

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

The following code example illustrates how to perform asynchronous read operations on the redirected P:System.Diagnostics.Process.StandardOutput stream of the sort command. The sort command is a console application that reads and sorts text input.

The example creates a T:System.Diagnostics.DataReceivedEventHandler delegate for the SortOutputHandler event handler and associates the delegate with the E:System.Diagnostics.Process.OutputDataReceived event. The event handler receives text lines from the redirected P:System.Diagnostics.Process.StandardOutput stream, formats the text, and writes the text to the screen.

No hay ningún ejemplo de código disponible o este idioma no es compatible.

.NET Framework
Disponible desde 2.0
Volver al principio
Mostrar: