Επεξεργασία

Κοινή χρήση μέσω


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)

Source:
Stream.cs
Source:
Stream.cs
Source:
Stream.cs

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

A task that represents the asynchronous read operation.

Exceptions

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

The cancellation token was canceled. This exception is stored into the returned task.

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)

Source:
Stream.cs
Source:
Stream.cs
Source:
Stream.cs

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

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.

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

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

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by ReadExactly(Byte[], Int32, Int32).

Applies to