dotnet / dotnet/dotnet-api-docs

Clarify documentation about DataReceivedEventHandler and DataReceivedEventArgs.Data

Open
#12,429 1 comment 0 reactions 0 assignees View on GitHub
area-System.Diagnostics untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

### 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":
```c#
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.