Skip to content

Clarify documentation about DataReceivedEventHandler and DataReceivedEventArgs.Data #12429

@fstanchina

Description

@fstanchina

Type of issue

Typo

Description

The documentation for DataReceivedEventArgs.Data states that an event with Data=null means that the stream has been closed. However, all the examples for DataReceivedEventHandler, DataReceivedEventArgs.Data and Process.OutputDataReceived are using String.IsNullOrEmpty() to check for null data, which is incorrect because it loses perfectly valid empty strings that correspond to empty lines in the program's output.

Also, the documentation for Process.OutputDataReceived doesn't say anything about null data or empty strings; I'd recommend to add a short note there too.

I'm proposing something like this for the examples, plus an explicit note saying "don't use IsNullOrEmpty(), it's incorrect":

    if (e.Data == null) {
        // end of stream
        return;
    }
    
    // e.Data could be empty ("") 
    Console.WriteLine(e.Data); 

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.datareceivedeventargs.data?view=netframework-4.8#system-diagnostics-datareceivedeventargs-data

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Diagnostics/DataReceivedEventArgs.xml

Document Version Independent Id

4dcc73b2-f80f-8645-e8a6-c07b922ad5e1

Platform Id

e0f0476d-88bd-231d-79cb-986db6c3d434

Article author

@dotnet-bot

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions