protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { _stream?.Dispose(); } }
/// <summary> /// Disconnects this connection. /// </summary> public void Disconnect() { if (_disconnectCalls > 0) { return; } _disconnectCalls++; _writeDone.WaitOne(); try { ClientDisconnected(this, EventArgs.Empty); } catch { // ignore } try { #if !NET452 RemoteClient.Dispose(); SecureStream?.Dispose(); NetworkStream?.Dispose(); #else RemoteClient.Close(); SecureStream?.Close(); NetworkStream?.Close(); #endif } catch { // ignored } finally { NetworkStream = null; SecureStream = null; RemoteClient = null; ContinuousReadingThread = null; } }