Socket.BeginDisconnect Method
Begins an asynchronous request to disconnect from a remote endpoint.
Namespace: System.Net.Sockets
Assembly: System (in System.dll)
[<HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading = true)>] member BeginDisconnect : reuseSocket:bool * callback:AsyncCallback * state:Object -> IAsyncResult
Parameters
- reuseSocket
- Type: System.Boolean
true if this socket can be reused after the connection is closed; otherwise, false.
- callback
- Type: System.AsyncCallback
The AsyncCallback delegate.
- state
- Type: System.Object
An object that contains state information for this request.
Return Value
Type: System.IAsyncResultAn IAsyncResult object that references the asynchronous operation.
| Exception | Condition |
|---|---|
| NotSupportedException | The operating system is Windows 2000 or earlier, and this method requires Windows XP. |
| ObjectDisposedException | The Socket object has been closed. |
| SocketException | An error occurred when attempting to access the socket. See the Remarks section for more information. |
If you are using a connection-oriented protocol, you can call the BeginDisconnect method to request a disconnect from a remote endpoint. If reuseSocket is true, you can reuse the socket.
The BeginDisconnect method uses a separate thread to invoke the specified callback method. The EndDisconnect method blocks until the pending disconnect is complete. For additional information on writing callback methods, see Callback Sample.
Note |
|---|
If you receive a SocketException exception, 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. |
Note |
|---|
This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing. |
Note |
|---|
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: ExternalThreading. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes. |
The following code example creates a socket for asynchronous communication and sends some data to a remote host. When the data has been sent, Shutdown is called to stop the send and receive activity. Then BeginDisconnect is called to begin a disconnect request. When the request completes, the Connected property is queried to test whether the socket is disconnected.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note