Stream.EndRead(IAsyncResult) Stream.EndRead(IAsyncResult) Stream.EndRead(IAsyncResult) Stream.EndRead(IAsyncResult) Method

定义

等待挂起的异步读取完成。Waits for the pending asynchronous read to complete. (请考虑改用 ReadAsync(Byte[], Int32, Int32)。)(Consider using ReadAsync(Byte[], Int32, Int32) instead.)

public:
 virtual int EndRead(IAsyncResult ^ asyncResult);
public virtual int EndRead (IAsyncResult asyncResult);
abstract member EndRead : IAsyncResult -> int
override this.EndRead : IAsyncResult -> int
Public Overridable Function EndRead (asyncResult As IAsyncResult) As Integer

参数

asyncResult
IAsyncResult IAsyncResult IAsyncResult IAsyncResult

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

返回

从流中读取的字节数,介于零 (0) 和所请求的字节数之间。The number of bytes read from the stream, between zero (0) and the number of bytes you requested. 流仅在流结尾返回零 (0),否则在至少有 1 个字节可用之前应一直进行阻止。Streams return zero (0) only at the end of the stream, otherwise, they should block until at least one byte is available.

异常

处于挂起状态的读取操作的句柄不可用。A handle to the pending read operation is not available.

-or-

挂起操作不支持读取。The pending operation does not support reading.

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

注解

在 .NET Framework 4 和更早的版本中,您必须使用 BeginReadEndRead 之类的方法来实现异步 I/O 操作。In the .NET Framework 4 and earlier versions, you have to use methods such as BeginRead and EndRead to implement asynchronous I/O operations. .NET Framework 4.5.NET Framework 4.5这些方法在中仍可用以支持旧版代码; 但是,新的异步方法( ReadAsync如、 WriteAsync CopyToAsync、和FlushAsync)可帮助你更轻松地实现异步 i/o 操作。These methods are still available in the .NET Framework 4.5.NET Framework 4.5 to support legacy code; however, the new async methods, such as ReadAsync, WriteAsync, CopyToAsync, and FlushAsync, help you implement asynchronous I/O operations more easily.

调用EndRead以确定从流中读取的字节数。Call EndRead to determine how many bytes were read from the stream.

EndRead每个IAsyncResultBeginRead调用一次。EndRead can be called once on every IAsyncResult from BeginRead.

此方法将一直阻塞,直到 I/O 操作已完成。This method blocks until the I/O operation has completed.

适用于

另请参阅