private async Task BackgroundProcessing(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { var workItem = await _actionQueue.DequeueAsync(stoppingToken); try { workItem(stoppingToken, _serviceScopeFactory); } catch (Exception ex) { _logger.LogError(ex, "Error occurred executing {WorkItem}.", nameof(workItem)); } } }