System.Net.Sockets.TcpClient.Dispose C# (CSharp) Method

Dispose() public method

public Dispose ( ) : void
return void
        public void Dispose()
        {
            Dispose(true);
        }

Same methods

TcpClient::Dispose ( bool disposing ) : void

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Dispose of the TCP client.
        /// </summary>
        /// <param name="disposing">Dispose of resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                try
                {
                    _WriteSemaphore.Wait();
                    _ReadSemaphore.Wait();

                    if (_SslStream != null)
                    {
                        _SslStream.Close();
                    }

                    if (_NetworkStream != null)
                    {
                        _NetworkStream.Close();
                    }

                    if (_TcpClient != null)
                    {
                        _TcpClient.Close();
                        _TcpClient.Dispose();
                        _TcpClient = null;
                    }
                }
                finally
                {
                    _ReadSemaphore.Release();
                    _WriteSemaphore.Release();
                }

                _IsConnected = false;
            }
        }
All Usage Examples Of System.Net.Sockets.TcpClient::Dispose