System.Net.Sockets.Socket.BeginDisconnect C# (CSharp) Method

BeginDisconnect() public method

public BeginDisconnect ( bool reuseSocket, AsyncCallback callback, object state ) : IAsyncResult
reuseSocket bool
callback AsyncCallback
state object
return IAsyncResult
        public IAsyncResult BeginDisconnect(bool reuseSocket, AsyncCallback callback, object state)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this);
            if (CleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            // Start context-flowing op.  No need to lock - we don't use the context till the callback.
            DisconnectOverlappedAsyncResult asyncResult = new DisconnectOverlappedAsyncResult(this, state, callback);
            asyncResult.StartPostingAsyncOp(false);

            // Post the disconnect.
            DoBeginDisconnect(reuseSocket, asyncResult);

            // Finish flowing (or call the callback), and return.
            asyncResult.FinishPostingAsyncOp();
            return asyncResult;
        }

Usage Example

示例#1
0
            public override void Close()
            {
                if (socket == null)
                {
                    return;
                }

                socket.BeginDisconnect(false, ar => {
                    Enqueue(delegate {
                        try {
                            ((System.Net.Sockets.Socket)ar.AsyncState).EndDisconnect(ar);
                            ((System.Net.Sockets.Socket)ar.AsyncState).Dispose();
                        } catch {
                        }

                        RaiseEndOfStream();
                        if (readTimer != null)
                        {
                            readTimer.Dispose();
                        }
                        if (writeTimer != null)
                        {
                            writeTimer.Dispose();
                        }
                        readTimer  = null;
                        writeTimer = null;
                        socket     = null;

                        base.Close();
                    });
                }, socket);
            }
All Usage Examples Of System.Net.Sockets.Socket::BeginDisconnect