Begins an asynchronous request for a remote host connection. The host is specified by an System.Net.IPAddress and a port number.
- callback
- Documentation for this section has not yet been entered.
- address
- The System.Net.IPAddress of the remote host.
- port
- The port number of the remote host.
- state
- A user-defined object that contains information about the connect operation. This object is passed to the requestCallback delegate when the operation is complete.
An IAsyncResult that references the asynchronous connection.
The asynchronous Socket.BeginConnect(System.Net.IPAddress, int, AsyncCallback, object) operation must be completed by calling the Socket.EndConnect(IAsyncResult) method. Typically, the method is invoked by the requestCallback 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.Connect method overloads, or Socket.EndConnect(IAsyncResult).
To cancel a pending call to the erload:System.Net.Sockets.Socket.BeginConnect method, close the System.Net.Sockets.Socket. When the Socket.Close method is called while an asynchronous operation is in progress, the callback provided to the erload:System.Net.Sockets.Socket.BeginConnect method is called. A subsequent call to the Socket.EndConnect(IAsyncResult) method will throw an ObjectDisposedException to indicate that the operation has been cancelled.
For detailed information about using the asynchronous programming model, see Asynchronous Programming Overview
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.
If this socket has previously been disconnected, then erload:System.Net.Sockets.Socket.BeginConnect must be called on a thread that will not exit until the operation is complete. This is a limitation of the underlying provider. Also the System.Net.EndPoint that is used must be different.
This member outputs trace information when you enable network tracing in your application. For more information, see [<topic://conUsingNetworkTracing>].
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.