NetworkStream.DataAvailable Property

Definition

Gets a value that indicates whether data is available on the NetworkStream to be immediately read.

C#
public virtual bool DataAvailable { get; }

Property Value

true if data is available on the stream to be read; otherwise, false.

Exceptions

The underlying Socket is closed.

Use the ErrorCode property to obtain the specific error code and refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

Remarks

Use the DataAvailable property to determine if data is queued to be immediately read. If DataAvailable is true, a call to Read returns immediately. If the remote host shuts down or closes the connection, DataAvailable may throw a SocketException.

Poznámka

Do not use DataAvailable to determine whether the transmission has ended. Even if there's no data available to be immediately read, the underlying socket may receive more data later.

Applies to

Produkt Verzie
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

See also