Ejemplo n.º 1
0
        private async Task StopService(
            IBackgroundService service,
            CancellationTokenSource cancellationTokenSource)
        {
            _logger.ServiceStopping(service);

            var stopwatch = Stopwatch.StartNew();

            try
            {
                await service.StopAsync(cancellationTokenSource.Token);

                _logger.ServiceStopped(service, stopwatch.Elapsed);
            }
            catch (Exception error)
            {
                _logger.ServiceStopFailed(service, stopwatch.Elapsed, error);
                cancellationTokenSource.Cancel(false);
                throw;
            }
        }