Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
SendAsync Method

Socket.SendAsync Method

Sends data asynchronously to a connected Socket object.

Namespace:  System.Net.Sockets
Assembly:  System.Net (in System.Net.dll)

public bool SendAsync(
	SocketAsyncEventArgs e


Type: System.Net.Sockets.SocketAsyncEventArgs
The System.Net.Sockets.SocketAsyncEventArgs object to use for this asynchronous socket operation.

Return Value

Type: System.Boolean
Returns true if the I/O operation is pending. The SocketAsyncEventArgs.Completed event on the System.Net.Sockets.SocketAsyncEventArgs object passed in the e parameter will be raised upon completion of the operation.
Returns false if the I/O operation completed synchronously. In this case, The SocketAsyncEventArgs.Completed event on the System.Net.Sockets.SocketAsyncEventArgs object passed in the e parameter will not be raised. The System.Net.Sockets.SocketAsyncEventArgs object passed in the e parameter may be examined immediately after the method call returns to retrieve the result of the operation.


The SocketAsyncEventArgs.Buffer or SocketAsyncEventArgs.BufferList properties on the System.Net.Sockets.SocketAsyncEventArgs object passed in the e parameter must reference valid buffers. One or the other of these properties may be set, but not both at the same time.


The value for an internal socket option associated with the Socket was incorrect.


A socket operation was already in progress using the System.Net.Sockets.SocketAsyncEventArgs object passed in the e parameter.


Windows XP or later is required for this method.


The Socket has been closed.


The Socket is not yet connected.

The SendAsync method is used to write outgoing data from one or more buffers on a connection-oriented socket. The SendAsync method starts an asynchronous send operation to the remote host established in the ConnectAsync method.

To be notified of completion, you must create a callback method that implements the EventHandler<SocketAsyncEventArgs> delegate and attach the callback to the SocketAsyncEventArgs.Completed event.

The following properties and events on the System.Net.Sockets.SocketAsyncEventArgs object are required to successfully call this method:

The caller may set the SocketAsyncEventArgs.UserToken property to any user state object desired before calling the SendAsync method, so that the information will be retrievable in the callback method. If the callback needs more information than a single object, a small class can be created to hold the other required state information as members.

A connection to the remote host using the Socket must be established before any data can be sent by the SendAsync method.


SendAsync method will throw an exception if you do not first call the ConnectAsync method to establish a connection.

Calling the SendAsync method gives you the ability to send data within a separate execution thread.

Note that the successful completion of the SendAsync method does not indicate that the data was successfully delivered.


If you receive a SocketException when calling this method, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets Error Codes documentation in the MSDN library for a detailed description of the error.


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

© 2015 Microsoft