System.Net.Sockets.SocketAsyncEventArgs.CancelConnectAsync C# (CSharp) Method

CancelConnectAsync() private method

private CancelConnectAsync ( ) : void
return void
        internal void CancelConnectAsync()
        {
            if (_operating == InProgress && _completedOperation == SocketAsyncOperation.Connect)
            {
                if (_multipleConnect != null)
                {
                    // If a multiple connect is in progress, abort it.
                    _multipleConnect.Cancel();
                }
                else
                {
                    // Otherwise we're doing a normal ConnectAsync - cancel it by closing the socket.
                    // _currentSocket will only be null if _multipleConnect was set, so we don't have to check.
                    if (_currentSocket == null)
                    {
                        NetEventSource.Fail(this, "CurrentSocket and MultipleConnect both null!");
                    }
                    _currentSocket.Dispose();
                }
            }
        }

Usage Example

Example #1
0
 public static void CancelConnectAsync(SocketAsyncEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     e.CancelConnectAsync();
 }
SocketAsyncEventArgs