private void CloseAndDisposeStan() { if (stanConnection != null) { stanConnection.Close(); stanConnection.Dispose(); } }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects). _connection?.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposedValue = true; } }
public Task StopAsync(CancellationToken cancellationToken) { if (!stoppedValue) { if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation($"Stopping hosted service \"{nameof(StanMessageReceiverService)}\"."); } try { _cancellationTokenSource?.Cancel(); if (_tasks != null) { try { Task.WaitAll(_tasks, 5000); } catch (AggregateException) { } } _connection?.Close(); _connection?.Dispose(); stoppedValue = true; if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation($"Stopped hosted service \"{nameof(StanMessageReceiverService)}\"."); } } catch (Exception e) { if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation($"Stopping hosted service \"{nameof(StanMessageReceiverService)}\" throws exception. {e.Message}"); } throw e; } } return(Task.CompletedTask); }
public void Dispose() { _connection?.Dispose(); }
public void Dispose() { _stanClient.Dispose(); }
public void Dispose() => _connection?.Dispose();