BufferedStream.EndRead(IAsyncResult) 方法

定义

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

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

参数

asyncResult
IAsyncResult

对所等待的挂起异步请求的引用。The reference to the pending asynchronous request to wait for.

返回

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

异常

asyncResultnullasyncResult is null.

IAsyncResult 对象不是通过对该类调用 BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) 来创建的。This IAsyncResult object was not created by calling BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) on this class.

注解

在 .NET Framework 4 及更早版本中,必须使用 BeginReadEndRead 等方法来实现异步文件操作。In the .NET Framework 4 and earlier versions, you have to use methods such as BeginRead and EndRead to implement asynchronous file operations. 这些方法在 .NET Framework 4.5.NET Framework 4.5 仍可用以支持旧版代码;但是,新的异步方法(如 ReadAsyncWriteAsyncFlushAsync)可帮助你更轻松地实现异步文件操作。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, and FlushAsync, help you implement asynchronous file operations more easily.

若要确定读取的字节数,必须用此 IAsyncResult 调用 EndReadEndRead must be called with this IAsyncResult to find out how many bytes were read.

适用于