Stream.EndRead(IAsyncResult) 方法


等待暫止的非同步讀取完成。Waits for the pending asynchronous read to complete. (請考慮改用 ReadAsync(Byte[], Int32, Int32)。)(Consider using ReadAsync(Byte[], Int32, Int32) instead.)

 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



待完成暫止非同步要求的參考。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),否則資料流應封鎖,直到至少有一個位元組為止。Streams return zero (0) only at the end of the stream, otherwise, they should block until at least one byte is available.


asyncResultnullasyncResult is null.

暫止讀取作業的控制代碼無法使用。A handle to the pending read operation is not available.


暫止的作業不支援讀取。The pending operation does not support reading.

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.


在 .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 中使用,以支援舊版程式碼;不過,新的非同步方法(例如 ReadAsyncWriteAsyncCopyToAsyncFlushAsync)可協助您更輕鬆地執行非同步 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 可以在來自 BeginRead的每個 IAsyncResult 上呼叫一次。EndRead can be called once on every IAsyncResult from BeginRead.

這個方法會封鎖,直到 I/O 作業完成為止。This method blocks until the I/O operation has completed.