private void Disconnect() { lock (_stateLock) { // Do nothing if the connection is offline if (State != ConnectionState.Disconnected) { // Change state before doing anything else in case something later in the method throws State = ConnectionState.Disconnected; Trace(TraceLevels.StateChanges, "Disconnected"); _disconnectTimeoutOperation.Dispose(); _disconnectCts.Cancel(); _disconnectCts.Dispose(); _receiveQueueMonitor.Dispose(); if (Monitor != null) { Monitor.Dispose(); } if (_transport != null) { Trace(TraceLevels.Events, "Transport.Dispose({0})", ConnectionId); _transport.Dispose(); _transport = null; } Trace(TraceLevels.Events, "Closed"); // Clear the state for this connection ConnectionId = null; ConnectionToken = null; GroupsToken = null; MessageId = null; _connectionData = null; _actualUrl = _userUrl; _actualQueryString = _userQueryString; // Clear the buffer // PORT: In 2.3.0 this was only present in the UWP and PCL versions. _traceWriter.Flush(); // TODO: Do we want to trigger Closed if we are connecting? OnClosed(); } } }
private void Disconnect() { lock (_stateLock) { // Do nothing if the connection is offline if (State != ConnectionState.Disconnected) { // Change state before doing anything else in case something later in the method throws State = ConnectionState.Disconnected; Trace(TraceLevels.StateChanges, "Disconnected"); _disconnectTimeoutOperation.Dispose(); _disconnectCts.Cancel(); _disconnectCts.Dispose(); _receiveQueueMonitor.Dispose(); if (Monitor != null) { Monitor.Dispose(); } if (_transport != null) { Trace(TraceLevels.Events, "Transport.Dispose({0})", ConnectionId); _transport.Dispose(); _transport = null; } Trace(TraceLevels.Events, "Closed"); // Clear the state for this connection ConnectionId = null; ConnectionToken = null; GroupsToken = null; MessageId = null; _connectionData = null; #if NETFX_CORE || PORTABLE // Clear the buffer _traceWriter.Flush(); #endif // TODO: Do we want to trigger Closed if we are connecting? OnClosed(); } } }