Stream.EndWrite(IAsyncResult) 方法

定義

結束非同步的寫入作業。Ends an asynchronous write operation. (請考慮用 WriteAsync(Byte[], Int32, Int32) 替代。)(Consider using WriteAsync(Byte[], Int32, Int32) instead.)

public:
 virtual void EndWrite(IAsyncResult ^ asyncResult);
public virtual void EndWrite (IAsyncResult asyncResult);
abstract member EndWrite : IAsyncResult -> unit
override this.EndWrite : IAsyncResult -> unit
Public Overridable Sub EndWrite (asyncResult As IAsyncResult)

參數

asyncResult
IAsyncResult

未處理的非同步 I/O 要求的參考。A reference to the outstanding asynchronous I/O request.

例外狀況

asyncResultnullasyncResult is null.

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

-或--or-

暫止的作業不支援寫入。The pending operation does not support writing.

asyncResult 不是來自目前資料流的 BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) 方法。asyncResult did not originate from a BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) method on the current stream.

資料流已關閉或發生內部錯誤。The stream is closed or an internal error has occurred.

備註

在 .NET Framework 4 (含) 以前版本中,您必須使用方法 (例如 BeginWriteEndWrite ) 實作非同步 I/O 作業。In the .NET Framework 4 and earlier versions, you have to use methods such as BeginWrite and EndWrite to implement asynchronous I/O operations. 這些方法仍.NET Framework 4.5.NET Framework 4.5可在中使用,以支援舊版程式碼; 不過,新的非同步方法( ReadAsync例如、 CopyToAsync WriteAsync、和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.

EndWrite在每個IAsyncResult BeginWrite上, 都必須只呼叫一次。EndWrite must be called exactly once on every IAsyncResult from BeginWrite.

這個方法會封鎖,直到 I/O 作業完成為止。This method blocks until the I/O operation has completed. 在非同步寫入要求期間發生的錯誤(例如 i/o 要求期間的磁片失敗)會發生線上程集區執行緒上,並且會在呼叫EndWrite時顯示。Errors that occur during an asynchronous write request, such as a disk failure during the I/O request, occur on the thread pool thread and become visible upon a call to EndWrite. 呼叫EndWrite時,不會顯示執行緒集區執行緒所擲回的例外狀況。Exceptions thrown by the thread pool thread will not be visible when calling EndWrite.

適用於

另請參閱