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

定义

开始异步读操作。

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

参数

buffer
Byte[]

将数据读入的缓冲区。

offset
Int32

buffer 中的字节偏移量,从此处开始读取。

count
Int32

最多读取的字节数。

callback
AsyncCallback

异步读操作完成后调用的方法。

state
Object

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

返回

IAsyncResult

引用异步读取的 IAsyncResult 对象。

属性

例外

buffernull

offset 小于 0。

  • 或 - count 小于 0。

count 大于 buffer 中可用的字节数。

管道已关闭。

管道不支持读操作。

管道已断开连接、正在等待连接或尚未设置句柄。

管道已中断或出现其他 I/O 错误。

注解

将返回 IAsyncResult 的对象传递给 EndRead 方法,以确定读取的字节数,并释放用于读取的操作系统资源。 EndRead 每次调用 BeginRead都必须调用一次。 这可以在调用 BeginRead 的相同代码中完成,也可以在传递给的 BeginRead回调中完成。

使用 CanRead 属性确定当前 PipeStream 对象是否支持读取操作。

如果管道已关闭或传递给 BeginRead无效参数,则立即引发相应的异常。 在执行请求的线程池线程上发生异步读取请求期间发生的错误。 当代码调用 EndRead 该方法时,将引发异常。

适用于