/// <inheritdoc/>
        public void Disconnect(DisconnectedEventArgs e = null)
        {
            var didDisconnect = false;

            if (!_isDisconnecting)
            {
                _isDisconnecting = true;
                try
                {
                    try
                    {
                        if (_sender != null)
                        {
                            _sender.Close();
                            _sender.Dispose();
                            didDisconnect = true;
                        }
                    }
#pragma warning disable CA1031 // Do not catch general exception types

                    // As ITransportSender is an extension point, we don't
                    // know what exceptions will be thrown by different implementations
                    // of ITransportSender.Close(). We do want to ensure that Disconnect doesn't
                    // stop the other resource cleanup, so we don't throw any exception.
                    // TODO: Flow ILogger all the way here and start logging these exceptions.
                    catch (Exception)
#pragma warning restore CA1031 // Do not catch general exception types
                    {
                    }

                    _sender = null;

                    if (didDisconnect)
                    {
                        _connectedEvent.Reset();
                        Disconnected?.Invoke(this, e ?? DisconnectedEventArgs.Empty);
                    }
                }
                finally
                {
                    _isDisconnecting = false;
                }
            }
        }
Пример #2
0
        /// <inheritdoc/>
        public void Disconnect(DisconnectedEventArgs e = null)
        {
            var didDisconnect = false;

            if (!_isDisconnecting)
            {
                _isDisconnecting = true;
                try
                {
                    try
                    {
                        if (_sender != null)
                        {
                            _sender.Close();
                            _sender.Dispose();
                            didDisconnect = true;
                        }
                    }
                    catch (Exception)
                    {
                    }

                    _sender = null;

                    if (didDisconnect)
                    {
                        _connectedEvent.Reset();
                        Disconnected?.Invoke(this, e ?? DisconnectedEventArgs.Empty);
                    }
                }
                finally
                {
                    _isDisconnecting = false;
                }
            }
        }