protected override void Dispose(bool disposing) { lock (_syncRoot) { if (!Disposed) { if (disposing) { try { _tcp.Client.Shutdown(SocketShutdown.Both); _tcp.Client.Disconnect(false); } catch (Exception) { Logger.LogWarning("Socket errored before shutdown and disconnect"); } _stream.Dispose(); _tcp.Dispose(); _keyGenerator.Dispose(); RemoteDisconnected = null; _tcp = null; _stream = null; } base.Dispose(disposing); } } }
protected virtual void Dispose(bool disposing) { lock (_syncRoot) { if (!Disposed) { if (disposing) { // dispose managed state (managed objects). try { _tcp.Client.Shutdown(SocketShutdown.Both); _tcp.Client.Disconnect(false); } catch (Exception) { Logger.LogWarning("Socket errored before shutdown and disconnect"); } _taskScheduler.Dispose(); _stream.Dispose(); _tcp.Dispose(); _disconnectTimer.Dispose(); _authenticator.Dispose(); _keyGenerator.Dispose(); Cryptor.Dispose(); RemoteClients.Clear(); } // free unmanaged resources (unmanaged objects) and override a finalizer below. // set large fields to null. _taskScheduler = null; _taskFactory = null; _tcp = null; _stream = null; _disconnectTimer = null; _authenticator = null; _keyGenerator = null; Disposed = true; } } }