protected override async Task ExecuteAsync(CancellationToken stoppingToken) { logger.LogDebug("Starting background task service"); while (!stoppingToken.IsCancellationRequested) { await Task.Delay(TimeSpan.FromMilliseconds(200), stoppingToken); if (!workerService.IsReady()) { continue; } try { var backgroundTask = (await workerService.DequeueAsync()).LastOrDefault(); logger.LogDebug("Dequeued run background task"); if (!workerService.IsReady() || backgroundTask == null) { continue; } logger.LogDebug("Worker hub run background task"); await workerHubContext.RunBackgroundTask(backgroundTask, token : stoppingToken); } catch (Exception e) { logger.LogError(e, $"An error occurred"); } } }