public async Task StartAsync(CancellationToken cancellationToken) { _logger.LogTrace("Starting the SyncHole service"); try { //Keep poling and uploading await new TaskFactory().StartNew(async() => { while (true) { if (cancellationToken.IsCancellationRequested) { break; } //create a new worker var worker = await _workerFactory.CreateWorkerAsync(); var hasWorker = worker != null; //execute the worker job if (hasWorker) { await RunNextWorkerAsync(worker); await _syncManifest.SaveAsync(); } //idle wait await _expBackoff.DelayAsync(!hasWorker); } }, cancellationToken); } catch (AggregateException) { //if the cancellation has been requested absorb the error if (!cancellationToken.IsCancellationRequested) { throw; } } }