Exemplo n.º 1
0
        /// <summary>
        /// Creates a new action queue.
        /// </summary>
        /// <param name="maxDegreeOfParallelism">the maximum number of parallel executing tasks</param>
        /// <param name="cancellationToken">the cancellation token</param>
        public ActionQueue(int maxDegreeOfParallelism          = 1,
                           int priorityCount                   = 1,
                           int boundedCapacity                 = int.MaxValue,
                           CompletionTracker tracker           = null,
                           CancellationToken cancellationToken = default(CancellationToken))
        {
            operationBlock = new ActionBlock <bool>(new Func <bool, Task>(Process), new ExecutionDataflowBlockOptions()
            {
                MaxDegreeOfParallelism = maxDegreeOfParallelism,
                CancellationToken      = cancellationToken,
            });

            priorityQueues = Enumerable
                             .Range(0, priorityCount * 2)
                             .Select(_ => new BlockingCollection <Func <Task> >(boundedCapacity))
                             .ToArray();

            this.tracker = tracker ?? new CompletionTracker();
        }
Exemplo n.º 2
0
 public CompletionHandle(CompletionTracker tracker)
 {
     this.tracker = tracker;
     tracker.OnStart();
 }