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

定义

开始执行异步读取操作。Begins an asynchronous read operation.

public:
 override IAsyncResult ^ BeginRead(cli::array <System::Byte> ^ buffer, int offset, int count, AsyncCallback ^ callback, System::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
Public Overrides Function BeginRead (buffer As Byte(), offset As Integer, count As Integer, callback As AsyncCallback, state As Object) As IAsyncResult

参数

buffer
Byte[]

将数据读入的缓冲区。The buffer to read data into.

offset
Int32

buffer 中的字节偏移量,从此处开始读取。The byte offset in buffer at which to begin reading.

count
Int32

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

callback
AsyncCallback

异步读操作完成后调用的方法。The method to call when the asynchronous read operation is completed.

state
Object

用户提供的对象,用于将此特定异步读取请求与其他请求区分开来。A user-provided object that distinguishes this particular asynchronous read request from other requests.

返回

引用异步读取的 IAsyncResult 对象。An IAsyncResult object that references the asynchronous read.

属性

异常

buffernullbuffer is null.

offset 小于 0。offset is less than 0.

- 或 --or- count 小于 0。count is less than 0.

count 大于 buffer 中可用的字节数。count is greater than the number of bytes available in buffer.

管道已关闭。The pipe is closed.

管道不支持读取操作。The pipe does not support read operations.

管道已断开连接,正在等待连接,或尚未设置句柄。The pipe is disconnected, waiting to connect, or the handle has not been set.

管道已损坏或出现其他 I/O 错误。The pipe is broken or another I/O error occurred.

注解

将返回的 IAsyncResult 对象传递到 EndRead 方法以确定读取的字节数,以及释放用于读取的操作系统资源。Pass the returned IAsyncResult object to the EndRead method to determine how many bytes were read and to release operating system resources used for reading. 对于每次调用 BeginRead,都必须调用 EndRead 一次。EndRead must be called once for every call to BeginRead. 这可以在调用 BeginRead 的同一代码中完成,也可以在传递给 BeginRead的回调中完成。This can be done either in the same code that called BeginRead or in a callback that is passed to BeginRead.

使用 CanRead 属性来确定当前 PipeStream 对象是否支持读操作。Use the CanRead property to determine whether the current PipeStream object supports read operations.

如果关闭管道或将无效参数传递到 BeginRead,则会立即引发相应的异常。If the pipe is closed or an invalid argument is passed to BeginRead, the appropriate exceptions are raised immediately. 在执行请求的线程池线程上发生异步读取请求期间发生的错误。Errors that occur during an asynchronous read request occur on the thread pool thread that is performing the request. 当代码调用 EndRead 方法时,将引发异常。The exceptions are raised when the code calls the EndRead method.

适用于