private void EnqueueTasks(ConcurrentDictionary <Task, Task> tasks, BulkImport <TIndexed> bulk, bool uncompletePartitions, TaskScheduler scheduler) { this.logger.LogTrace("()"); if (!uncompletePartitions && !bulk.HasFullPartition) { this.logger.LogTrace("(-):PARTITIONS {0}:{1},{2}:{3}", nameof(uncompletePartitions), uncompletePartitions, nameof(bulk.HasFullPartition), bulk.HasFullPartition); return; } if (uncompletePartitions) { bulk.FlushUncompletePartitions(); } while (bulk._ReadyPartitions.Count != 0) { var item = bulk._ReadyPartitions.Dequeue(); var task = retry.Do(() => IndexCore(item.Item1, item.Item2), scheduler); tasks.TryAdd(task, task); task.ContinueWith(prev => { _Exception = prev.Exception ?? _Exception; tasks.TryRemove(prev, out prev); }); if (tasks.Count > MaxQueued) { WaitFinished(tasks, MaxQueued / 2); } } this.logger.LogTrace("(-)"); }