Redigera

Dela via


Socket.EndConnect(IAsyncResult) Method

Definition

Ends a pending asynchronous connection request.

public:
 void EndConnect(IAsyncResult ^ asyncResult);
public void EndConnect (IAsyncResult asyncResult);
member this.EndConnect : IAsyncResult -> unit
Public Sub EndConnect (asyncResult As IAsyncResult)

Parameters

asyncResult
IAsyncResult

An IAsyncResult that stores state information and any user defined data for this asynchronous operation.

Exceptions

asyncResult is null.

asyncResult was not returned by a call to the BeginConnect(EndPoint, AsyncCallback, Object) method.

EndConnect(IAsyncResult) was previously called for the asynchronous connection.

An error occurred when attempting to access the socket.

-or-

.NET 7+ only: The Socket has been closed.

.NET Framework, .NET Core, and .NET 5-6 only: The Socket has been closed.

Remarks

Important

This is a compatibility API. We don't recommend using the APM (Begin* and End*) methods for new development. Instead, use the Task-based equivalents.

EndConnect completes the operation started by BeginConnect. You need to pass the IAsyncResult created by the matching BeginConnect call. EndConnect will block the calling thread until the operation is completed.

Note

If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code.

Note

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in .NET Framework.

Applies to

See also