Stream.ReadExactlyAsync Method

Definition

Overloads

ReadExactlyAsync(Memory<Byte>, CancellationToken)

Asynchronously reads bytes from the current stream, advances the position within the stream until the buffer is filled, and monitors cancellation requests.

ReadExactlyAsync(Byte[], Int32, Int32, CancellationToken)

Asynchronously reads count number of bytes from the current stream, advances the position within the stream, and monitors cancellation requests.

ReadExactlyAsync(Memory<Byte>, CancellationToken)

Asynchronously reads bytes from the current stream, advances the position within the stream until the buffer is filled, and monitors cancellation requests.

public System.Threading.Tasks.ValueTask ReadExactlyAsync (Memory<byte> buffer, System.Threading.CancellationToken cancellationToken = default);
member this.ReadExactlyAsync : Memory<byte> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask
Public Function ReadExactlyAsync (buffer As Memory(Of Byte), Optional cancellationToken As CancellationToken = Nothing) As ValueTask

Parameters

buffer
Memory<Byte>

The buffer to write the data into.

cancellationToken
CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask

A task that represents the asynchronous read operation.

Exceptions

The end of the stream is reached before filling the buffer.

Remarks

When buffer is empty, this read operation will be completed without waiting for available data in the stream.

Applies to

ReadExactlyAsync(Byte[], Int32, Int32, CancellationToken)

Asynchronously reads count number of bytes from the current stream, advances the position within the stream, and monitors cancellation requests.

public System.Threading.Tasks.ValueTask ReadExactlyAsync (byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken = default);
member this.ReadExactlyAsync : byte[] * int * int * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask
Public Function ReadExactlyAsync (buffer As Byte(), offset As Integer, count As Integer, Optional cancellationToken As CancellationToken = Nothing) As ValueTask

Parameters

buffer
Byte[]

The buffer to write the data into.

offset
Int32

The byte offset in buffer at which to begin writing data from the stream.

count
Int32

The number of bytes to be read from the current stream.

cancellationToken
CancellationToken

The token to monitor for cancellation requests.

Returns

ValueTask

A task that represents the asynchronous read operation.

Exceptions

buffer is null.

offset is outside the bounds of buffer.

-or-

count is negative.

-or-

The range specified by the combination of offset and count exceeds the length of buffer.

The end of the stream is reached before reading count number of bytes.

Remarks

When count is 0 (zero), this read operation will be completed without waiting for available data in the stream.

Applies to