UnmanagedMemoryStream.ReadAsync 方法

定义

重载

ReadAsync(Memory<Byte>, CancellationToken)

以异步方式将非管理的内存流字节读入内存区域。Asynchronously reads the unmanaged memory stream bytes into the memory region.

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

将指定数量的字节异步读入指定的数组。Asynchronously reads the specified number of bytes into the specified array.

ReadAsync(Memory<Byte>, CancellationToken)

以异步方式将非管理的内存流字节读入内存区域。Asynchronously reads the unmanaged memory stream bytes into the memory region.

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

参数

buffer
Memory<Byte>

异步方法完成后,此内存区域包含从非管理的内存流中读取的所有字节。When the asynchronous method finishes, this memory region contains all the bytes read from the unmanaged memory stream.

cancellationToken
CancellationToken

要监视取消请求的标记。The token to monitor for cancellation requests. 默认值是 NoneThe default value is None.

返回

ValueTask<Int32>

一个表示异步读取操作并将读取的总字节数包装到缓冲区中的任务。A task that represents the asynchronous read operation, and wraps the total number of bytes read into the buffer.

适用于

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

将指定数量的字节异步读入指定的数组。Asynchronously reads the specified number of bytes into the specified array.

public:
 override System::Threading::Tasks::Task<int> ^ ReadAsync(cli::array <System::Byte> ^ buffer, int offset, int count, System::Threading::CancellationToken cancellationToken);
public override System.Threading.Tasks.Task<int> ReadAsync (byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken);
[System.Runtime.InteropServices.ComVisible(false)]
public override System.Threading.Tasks.Task<int> ReadAsync (byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken);
override this.ReadAsync : byte[] * int * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.ReadAsync : byte[] * int * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
Public Overrides Function ReadAsync (buffer As Byte(), offset As Integer, count As Integer, cancellationToken As CancellationToken) As Task(Of Integer)

参数

buffer
Byte[]

要写入数据的缓冲区。The buffer to write the data into.

offset
Int32

buffer 中的字节偏移量,从该偏移量开始写入从流中读取的数据。The byte offset in buffer at which to begin writing data from the stream.

count
Int32

最多读取的字节数。The maximum number of bytes to read.

cancellationToken
CancellationToken

要监视取消请求的标记。The token to monitor for cancellation requests. 默认值是 NoneThe default value is None.

返回

Task<Int32>

表示异步读取操作的任务。A task that represents the asynchronous read operation. TResult 参数的值包含读入缓冲区的总字节数。The value of the TResult parameter contains the total number of bytes read into the buffer. 如果当前可用字节数少于所请求的字节数,则该结果值可小于所请求的字节数;如果已到达流结尾时,则为 0(零)。The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the stream has been reached.

属性

注解

如果在读取操作过程中发生异常,则该异常将被设置为 Task.Exception 返回的任务的属性的。If an exception occurs during the read operation, it will be set as the Task.Exception of the property of the returned task.

适用于