System.IO.FileStream.EndWrite Method

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.)

Syntax

public override void EndWrite (IAsyncResult asyncResult)

Parameters

asyncResult
The pending asynchronous I/O request.

Exceptions

TypeReason
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 .

Remarks

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.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0