DeflateStream.BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) 方法

定义

开始异步读操作。 (请考虑改用 ReadAsync(Byte[], Int32, Int32) 方法。)

public:
 override IAsyncResult ^ BeginRead(cli::array <System::Byte> ^ buffer, int offset, int count, AsyncCallback ^ asyncCallback, System::Object ^ asyncState);
public:
 override IAsyncResult ^ BeginRead(cli::array <System::Byte> ^ array, int offset, int count, AsyncCallback ^ asyncCallback, System::Object ^ asyncState);
public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState);
public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState);
public override IAsyncResult BeginRead (byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState);
override this.BeginRead : byte[] * int * int * AsyncCallback * obj -> IAsyncResult
override this.BeginRead : byte[] * int * int * AsyncCallback * obj -> IAsyncResult
Public Overrides Function BeginRead (buffer As Byte(), offset As Integer, count As Integer, asyncCallback As AsyncCallback, asyncState As Object) As IAsyncResult
Public Overrides Function BeginRead (array As Byte(), offset As Integer, count As Integer, asyncCallback As AsyncCallback, asyncState As Object) As IAsyncResult

参数

bufferarray
Byte[]

将数据读入的字节数组。

offset
Int32

从流中开始读取数据的字节偏移量。

count
Int32

最多读取的字节数。

asyncCallback
AsyncCallback

可选的异步回调,在完成读取操作时调用。

asyncState
Object

一个用户提供的对象,它将该特定的异步读取请求与其他请求区别开来。

返回

表示异步读取操作(可能仍处于挂起状态)的对象。

例外

尝试异步读取超过了流的结尾,或者发生了磁盘错误。

一个或多个自变量无效。

在流关闭后调用方法。

当前 DeflateStream 实现不支持读取操作。

无法完成此调用。

注解

重要

从 .NET 6 开始,此方法读取的字节数可能与请求的字节数不一样多。 有关详细信息,请参阅 DeflateStream、GZipStream 和 CryptoStream 中的部分读取和零字节读取

从 .NET Framework 4.5 开始,可以使用 方法执行异步读取操作ReadAsync。 方法 BeginRead 在当前版本中仍可用,以支持旧代码;但是,通过使用新的异步方法,可以更轻松地实现异步 I/O 操作。 有关详细信息,请参阅异步文件 I/O

IAsyncResult 返回值传递给 EndRead 流的 方法,以确定读取的字节数并释放用于读取的操作系统资源。 为此,可以使用调用 或 传递到 的回调中调用 BeginRead 或 的 BeginRead相同代码。

当发出异步读取或写入操作时,而不是 I/O 操作完成时,流中的当前位置会更新。

多个同步异步请求使请求完成顺序不确定。

CanRead使用 属性可确定当前DeflateStream对象是否支持读取。

如果流关闭或传递了无效参数,则会立即从 BeginRead引发异常。 异步读取请求期间发生的错误(例如 I/O 请求期间的磁盘故障)发生在线程池线程上,并在调用 EndRead时引发异常。

适用于