Ends an asynchronous write operation and blocks until the I/O operation is complete. (Consider using FileStream.WriteAsync(Byte[], int, int, System.Threading.CancellationToken) instead; see the Remarks section.)
Type Reason ArgumentNullException asyncResult is null. ArgumentException asyncResult was not returned by a call to FileStream.BeginWrite(Byte[], int, int, AsyncCallback, object). InvalidOperationException FileStream.EndWrite(IAsyncResult) was called multiple times with asyncResult .
In the .NET Framework 4 and earlier versions, you have to use methods such as FileStream.BeginWrite(Byte[], int, int, AsyncCallback, object) and FileStream.EndWrite(IAsyncResult) to implement asynchronous file operations. These methods are still available in the net_v45 to support legacy code; however, the new async methods, such as FileStream.ReadAsync(Byte[], int, int, System.Threading.CancellationToken), FileStream.WriteAsync(Byte[], int, int, System.Threading.CancellationToken), Stream.CopyToAsync(Stream), and FileStream.FlushAsync(System.Threading.CancellationToken), help you implement asynchronous file operations more easily.
This method overrides Stream.EndWrite(IAsyncResult).
FileStream.EndWrite(IAsyncResult) must be called exactly once on every IAsyncResult from FileStream.BeginWrite(Byte[], int, int, AsyncCallback, object). FileStream.EndWrite(IAsyncResult) will block until the I/O operation has completed.