DeflateStream.ReadAsync 方法

定义

重载

ReadAsync(Memory<Byte>, CancellationToken)

从当前 Deflate 流异步读取字节的序列,将其写入字节内存范围,按读取的字节数向前移动 Deflate 流中的位置,并监视取消请求。Asynchronously reads a sequence of bytes from the current Deflate stream, writes them to a byte memory range, advances the position within the Deflate stream by the number of bytes read, and monitors cancellation requests.

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

从当前 Deflate 流异步读取字节的序列,将其写入字节数组,按读取的字节数向前移动 Deflate 流中的位置,并监视取消请求。Asynchronously reads a sequence of bytes from the current Deflate stream, writes them to a byte array, advances the position within the Deflate stream by the number of bytes read, and monitors cancellation requests.

ReadAsync(Memory<Byte>, CancellationToken)

从当前 Deflate 流异步读取字节的序列,将其写入字节内存范围,按读取的字节数向前移动 Deflate 流中的位置,并监视取消请求。Asynchronously reads a sequence of bytes from the current Deflate stream, writes them to a byte memory range, advances the position within the Deflate stream by the number of bytes read, and monitors cancellation requests.

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>

参数

buffer
Memory<Byte>

要将数据写入的内存区域。The region of memory to write the data into.

cancellationToken
CancellationToken

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

返回

一个表示异步读取操作并将读取的总字节数包装到缓冲区中的任务。A task that represents the asynchronous read operation, which wraps the total number of bytes read into the buffer. 如果很多字节当前不可用,则结果值可小于在缓冲区中分配的字节数;如果已到达 Deflate 流结尾,则结果值可以为 0(零)。The result value can be less than the number of bytes allocated in the buffer if that many bytes are not currently available, or it can be 0 (zero) if the end of the Deflate stream has been reached.

注解

利用 ReadAsync 方法,你可以在不阻塞主线程的情况下执行占用大量资源的 i/o 操作。The ReadAsync method enables you to perform resource-intensive I/O operations without blocking the main thread. Windows 8.x 应用商店Windows 8.x Store 应用或 桌面desktop 应用中一个耗时的流操作可能阻塞 UI 线程并让您的应用看起来好像不工作时,这种性能的考虑就显得尤为重要了。This performance consideration is particularly important in a Windows 8.x 应用商店Windows 8.x Store app or 桌面desktop app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. 异步方法与 Visual Basic 和C#中的 asyncawait 关键字结合使用。The async methods are used in conjunction with the async and await keywords in Visual Basic and C#.

使用 CanRead 属性可确定当前实例是否支持读取。Use the CanRead property to determine whether the current instance supports reading.

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

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

从当前 Deflate 流异步读取字节的序列,将其写入字节数组,按读取的字节数向前移动 Deflate 流中的位置,并监视取消请求。Asynchronously reads a sequence of bytes from the current Deflate stream, writes them to a byte array, advances the position within the Deflate stream by the number of bytes read, and monitors cancellation requests.

public:
 override System::Threading::Tasks::Task<int> ^ ReadAsync(cli::array <System::Byte> ^ array, int offset, int count, System::Threading::CancellationToken cancellationToken);
public override System.Threading.Tasks.Task<int> ReadAsync (byte[] array, int offset, int count, System.Threading.CancellationToken cancellationToken);
override this.ReadAsync : byte[] * int * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>

参数

array
Byte[]

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

offset
Int32

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

count
Int32

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

cancellationToken
CancellationToken

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

返回

一个表示异步读取操作(将读取的总字节数包装到 array 中)的任务。A task that represents the asynchronous read operation, which wraps the total number of bytes read into the array. 如果当前可用字节数少于所请求的字节数,则该结果值可小于所请求的字节数;如果已到达 Deflate 流结尾时,则为 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 Deflate stream has been reached.

注解

利用 ReadAsync 方法,你可以在不阻塞主线程的情况下执行占用大量资源的 i/o 操作。The ReadAsync method enables you to perform resource-intensive I/O operations without blocking the main thread. Windows 8.x 应用商店Windows 8.x Store 应用或 桌面desktop 应用中一个耗时的流操作可能阻塞 UI 线程并让您的应用看起来好像不工作时,这种性能的考虑就显得尤为重要了。This performance consideration is particularly important in a Windows 8.x 应用商店Windows 8.x Store app or 桌面desktop app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. 异步方法与 Visual Basic 和C#中的 asyncawait 关键字结合使用。The async methods are used in conjunction with the async and await keywords in Visual Basic and C#.

使用 CanRead 属性可确定当前实例是否支持读取。Use the CanRead property to determine whether the current instance supports reading.

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

适用于