示例#1
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_transport != null)
         {
             _transport.Dispose();
         }
     }
 }
示例#2
0
        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();
                }
            }
        }
示例#3
0
        protected virtual void Dispose(bool isDisposing)
        {
            if (_isDisposed)
            {
                return;
            }
            _isDisposed = true;

            if (isDisposing)
            {
                Disconnect().Wait(5000);
                _clientTransport.Dispose();
            }
        }
示例#4
0
        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();
                }
            }
        }