PipeStream.EndRead(IAsyncResult) 方法


结束挂起的异步读取请求。Ends a pending asynchronous read request.

 override int EndRead(IAsyncResult ^ asyncResult);
public override int EndRead (IAsyncResult asyncResult);
public override int EndRead (IAsyncResult asyncResult);
override this.EndRead : IAsyncResult -> int
Public Overrides Function EndRead (asyncResult As IAsyncResult) As Integer



对挂起的异步请求的引用。The reference to the pending asynchronous request.


已读取的字节数。The number of bytes that were read. 返回值 0 指示已到达流的末尾(管道已关闭)。A return value of 0 indicates the end of the stream (the pipe has been closed).



asyncResultnullasyncResult is null.

asyncResult 不源于当前流的 BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) 方法。asyncResult did not originate from a BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) method on the current stream.

流已关闭或出现了内部错误。The stream is closed or an internal error has occurred.


此方法返回对 BeginRead的之前调用指定的字节数组中读取的字节数。This method returns the number of bytes read into the byte array specified by the earlier call to BeginRead.

将返回的 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.