BufferedStream.EndWrite(IAsyncResult) 方法


结束异步写入操作,在 I/O 操作完成之前一直阻止。Ends an asynchronous write operation and blocks until the I/O operation is complete. (请考虑改用 WriteAsync(Byte[], Int32, Int32, CancellationToken)。)(Consider using WriteAsync(Byte[], Int32, Int32, CancellationToken) instead.)

 override void EndWrite(IAsyncResult ^ asyncResult);
public override void EndWrite (IAsyncResult asyncResult);
override this.EndWrite : IAsyncResult -> unit
Public Overrides Sub EndWrite (asyncResult As IAsyncResult)



挂起的异步请求。The pending asynchronous request.


asyncResultnullasyncResult is null.

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


在 .NET Framework 4 及更早版本中,必须使用 BeginWriteEndWrite 等方法来实现异步文件操作。In the .NET Framework 4 and earlier versions, you have to use methods such as BeginWrite and EndWrite 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.

对于每个调用 BeginRead,必须只调用一次 EndWriteEndWrite must be called exactly once for every call to BeginRead. 在开始另一个读取操作之前未能结束读取进程可能会导致死锁或其他不需要的行为。Failing to end a read process before beginning another read operation can cause deadlock or other undesirable behavior.