System.IO.Stream.EndRead Method

Waits for the pending asynchronous read to complete. (Consider using Stream.ReadAsync(Byte[], int, int) instead; see the Remarks section.)

Syntax

public virtual int EndRead (IAsyncResult asyncResult)

Parameters

asyncResult
The reference to the pending asynchronous request to finish.

Returns

The number of bytes read from the stream, between zero (0) and the number of bytes you requested. Streams return zero (0) only at the end of the stream, otherwise, they should block until at least one byte is available.

Exceptions

TypeReason
ArgumentNullException asyncResult is null.
ArgumentException asyncResult did not originate from a Stream.BeginRead(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.BeginRead(Byte[], int, int, AsyncCallback, object) and Stream.EndRead(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.

Call EndRead to determine how many bytes were read from the stream.

EndRead can be called once on every IAsyncResult from Stream.BeginRead(Byte[], int, int, AsyncCallback, object).

This method blocks 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