System.Net.Sockets.Socket.BeginReceive Method

Begins to asynchronously receive data from a connected System.Net.Sockets.Socket.

Syntax

[System.CLSCompliant(false)]
public IAsyncResult BeginReceive (IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, AsyncCallback callback, object state)

Parameters

buffers
An array of type byte that is the storage location for the received data.
socketFlags
A bitwise combination of the System.Net.Sockets.SocketFlags values.
callback
An AsyncCallback delegate that references the method to invoke when the operation is complete.
state
A user-defined object that contains information about the receive operation. This object is passed to the Socket.EndReceive(IAsyncResult) delegate when the operation is complete.

Returns

An IAsyncResult that references the asynchronous read.

Remarks

The asynchronous Socket.BeginReceive(Byte[], int, int, SocketFlags, AsyncCallback, object) operation must be completed by calling the Socket.EndReceive(IAsyncResult) method. Typically, the method is invoked by the callback delegate.

This method does not block until the operation is complete. To block until the operation is complete, use one of the erload:System.Net.Sockets.Socket.Receive method overloads.

To cancel a pending erload:System.Net.Sockets.Socket.BeginReceive, call the Socket.Close method.

For detailed information about using the asynchronous programming model, see Asynchronous Programming Overview.

Note:

If you receive a System.Net.Sockets.SocketException, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

Note:

All I/O initiated by a given thread is canceled when that thread exits. A pending asynchronous operation can fail if the thread exits before the operation completes.

Note:

state is an instantiation of a user-defined class.

Note:

This member outputs trace information when you enable network tracing in your application. For more information, see [<topic://conUsingNetworkTracing>].

Note:

The execution context (the security context, the impersonated user, and the calling context) is cached for the asynchronous System.Net.Sockets.Socket methods. After the first use of a particular context (a specific asynchronous System.Net.Sockets.Socket method, a specific System.Net.Sockets.Socket instance, and a specific callback), subsequent uses of that context will see a performance improvement.

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0