CryptoStream.ReadAsync(Byte[], Int32, Int32, CancellationToken) 方法

定义

从当前流异步读取字节序列,将此流中的位置提升读取的字节数,并监视取消请求数。Reads a sequence of bytes from the current stream asynchronously, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

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);
override this.ReadAsync : byte[] * int * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>

参数

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.

返回

表示异步读取操作的任务。A task that represents the asynchronous read operation. 目标对象的 TResult 参数的值包含多次读入缓冲区总字节数。The value of the task object's TResult parameter contains the total number of bytes read into the buffer. 如果当前可用字节数少于所请求的字节数,则该结果值可能小于所请求的字节数,或者如果已到达流的末尾时,则为 0(零)。The result 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.

异常

buffernullbuffer is null.

offsetcount 为负数。offset or count is negative.

offsetcount 的总和大于缓冲区长度。The sum of offset and count is larger than the buffer length.

流不支持读取。The stream does not support reading.

已释放流。The stream has been disposed.

之前的读取操作当前正在使用流。The stream is currently in use by a previous read operation.

注解

必须先将对的调用 ReadAsyncawait (C#)或 Await (Visual Basic)运算符,才能暂停执行方法,直到任务完成。You must preface your call to ReadAsync with the await (C#) or Await (Visual Basic) operator to suspend execution of the method until the task is complete. 有关详细信息,请参阅使用 Async 和 Await 的异步编程For more information, see Asynchronous Programming with Async and Await.

如果在操作完成前取消该操作,则返回的任务将包含 Status 属性的 Canceled 值。If the operation is canceled before it completes, the returned task contains the Canceled value for the Status property.

适用于

另请参阅