Επεξεργασία

Κοινή χρήση μέσω


Socket.BeginDisconnect(Boolean, AsyncCallback, Object) Method

Definition

Begins an asynchronous request to disconnect from a remote endpoint.

public:
 IAsyncResult ^ BeginDisconnect(bool reuseSocket, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginDisconnect (bool reuseSocket, AsyncCallback? callback, object? state);
public IAsyncResult BeginDisconnect (bool reuseSocket, AsyncCallback callback, object state);
member this.BeginDisconnect : bool * AsyncCallback * obj -> IAsyncResult
Public Function BeginDisconnect (reuseSocket As Boolean, callback As AsyncCallback, state As Object) As IAsyncResult

Parameters

reuseSocket
Boolean

true if this socket can be reused after the connection is closed; otherwise, false.

callback
AsyncCallback

The AsyncCallback delegate.

state
Object

An object that contains state information for this request.

Returns

An IAsyncResult object that references the asynchronous operation.

Exceptions

The Socket object has been closed.

.NET Framework and .NET 5 and earlier only: An error occurred when attempting to access the socket.

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.

If you are using a connection-oriented protocol, you can call the BeginDisconnect method to initiate disconnection from a remote endpoint. If reuseSocket is true, you can reuse the socket.

You can pass a callback that implements AsyncCallback to BeginDisconnect in order to get notified about the completion of the disconnect operation. Note that if the underlying network stack completes the operation synchronously, the callback might be executed inline, during the call to BeginDisconnect. In this case, the CompletedSynchronously property on the returned IAsyncResult will be set to true to indicate that the method completed synchronously. Use the AsyncState property of the IAsyncResult to obtain the state object passed to the BeginDisconnect method.

The BeginDisconnect operation must be completed by calling the EndDisconnect method. Typically, the method is invoked by the provided AsyncCallback delegate. EndDisconnect will block the calling thread until the operation is completed.

Note

If you receive a SocketException exception, 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