Socket.BeginDisconnect(Boolean, AsyncCallback, Object) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
- 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.
An IAsyncResult object that references the asynchronous operation.
The Socket object has been closed.
.NET Framework and .NET 5 and earlier only: An error occurred when attempting to access the socket.
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.
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: