System.IO.Stream.EndWrite Method

Ends an asynchronous write operation. (Consider using Stream.WriteAsync(Byte[], int, int) instead; see the Remarks section.)

Syntax

public virtual void EndWrite (IAsyncResult asyncResult)

Parameters

asyncResult
A reference to the outstanding asynchronous I/O request.

Exceptions

TypeReason
ArgumentNullExceptionThe asyncResult parameter is null.
ArgumentException asyncResult did not originate from a Stream.BeginWrite(Byte[], int, int, AsyncCallback, object) method on the current stream.

Remarks

In the .NET Framework 4 and earlier versions, you have to use methods such as Stream.BeginWrite(Byte[], int, int, AsyncCallback, object) and Stream.EndWrite(IAsyncResult) to implement asynchronous I/O operations. These methods are still available in the net_v45 to support legacy code; however, the new async methods, such as Stream.ReadAsync(Byte[], int, int), Stream.WriteAsync(Byte[], int, int), Stream.CopyToAsync(Stream), and Stream.FlushAsync, help you implement asynchronous I/O operations more easily.

EndWrite must be called exactly once on every IAsyncResult from Stream.BeginWrite(Byte[], int, int, AsyncCallback, object).

This method blocks until the I/O operation has completed. 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. Exceptions thrown by the thread pool thread will not be visible when calling EndWrite.

Requirements

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