示例#1
0
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            Task.Run(() =>
            {
                try
                {
                    _logger.LogInformation("Subscribed to Price");
                    _priceSubscriber.Consume(stoppingToken);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Unknown error found in PriceBackgroundService {e.Message} {e.StackTrace}");
                }
            }, stoppingToken);

            return(Task.CompletedTask);
        }
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            Task.Run(() =>
            {
                try
                {
                    stoppingToken.ThrowIfCancellationRequested();
                    _logger.LogInformation($"Subscribed to PriceSubscriberService");
                    _priceSubscriber.Consume(stoppingToken);
                }
                catch (OperationCanceledException ox)
                {
                    _logger.LogError($"Cancellation Invoked {ox.Message} \n\nRetry after 5 secs");
                }
                catch (Exception e)
                {
                    _logger.LogError($"Unknown error found in PriceBackgroundService {e.Message} {e.StackTrace}");
                }
            }, stoppingToken);

            return(Task.CompletedTask);
        }