예제 #1
0
 private void CloseAndDisposeStan()
 {
     if (stanConnection != null)
     {
         stanConnection.Close();
         stanConnection.Dispose();
     }
 }
예제 #2
0
        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);
        }
예제 #4
0
 public void Dispose()
 {
     _connection?.Dispose();
 }
예제 #5
0
 public void Dispose()
 {
     _stanClient.Dispose();
 }
예제 #6
0
 public void Dispose() => _connection?.Dispose();