/// <summary> /// Disposes objected used by the class. /// </summary> /// <param name="disposing">A Boolean that indicates whether the method call comes from a Dispose method (its value is true) or from a finalizer (its value is false).</param> /// <remarks> /// The disposing parameter should be false when called from a finalizer, and true when called from the IDisposable.Dispose method. /// In other words, it is true when deterministically called and false when non-deterministically called. /// </remarks> protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { // Dispose managed objects owned by the class here. _sender?.Dispose(); _sendQueue?.Dispose(); _connectedEvent?.Dispose(); } _disposed = true; }
/// <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; } } }
/// <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; } } }