protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { bool failed = FailedUploads.Any(); if (failed) { await TryToUploadFailed(); } } }
private async Task TryToUploadFailed() { await Task.Run(async() => { while (FailedUploads.Any()) { FailedUploads.TryDequeue(out string current); var success = UploadAction(current); if (success) { _logger.LogInformation($"Uploaded {current} at {DateTime.Now.ToLongDateString()} from failed uploads"); File.Delete(current); } else { FailedUploads.Enqueue(current); } } await Task.CompletedTask; }); // awaiting 5 mins before we try again Thread.Sleep(DelayAwait); }