private async Task ProcessNextStepAsync(List <VesselAisUpdateModel> updateList) { List <VesselUpdateModel> updatedVesselsStep = new List <VesselUpdateModel>(); try { List <Task> currentRunningTasks = new List <Task>(); CancellationTokenSource tokenSource = GetCancellationTokenSource(); SemaphoreSlim semaphoreThrottel = GetSemaphoreThrottel(); for (int i = _counter; i < _progress.GetCurrentUpdateStep(_counter, _configuration.GetValue <int>("Iteration:Step")); i++) { int iteration = i; currentRunningTasks.Add(Task.Run(async() => { VesselUpdateModel updatedVessel = await _vesselUpdates.GetVesselUpdatesAsync(updateList[iteration], tokenSource.Token, semaphoreThrottel); _progress.UpdateMissingProperties(updatedVessel); _progress.SetLastUpdatedVessel(_stringParser.BuildUpdatedVesselInfo(updatedVessel)); lock (((ICollection)updatedVesselsStep).SyncRoot) { updatedVesselsStep.Add(updatedVessel); } _counter++; }, tokenSource.Token)); } await Task.WhenAll(currentRunningTasks); } catch (Exception ex) { _counter++; _progress.SetLastError(ex.Message + " from: " + _exceptionProcessor.GetMethodNameThrowingException(ex)); } finally { _progress.SetUpdatingDatabaseTrue(); SaveUpdatedVesselsStep(updatedVesselsStep); _progress.SetUpdatingDatabaseFalse(); } }