public TaskDispatcher(byte maxConcurrency, IExecutionQueue[] executionQueues) { if (maxConcurrency == 0) { throw new ArgumentOutOfRangeException("maxConcurrency", "MaxConcurrency should be greater than zero."); } if (executionQueues == null) { throw new ArgumentNullException("executionQueues"); } if (executionQueues.Length == 0) { throw new ArgumentOutOfRangeException("executionQueues", "List of execution queues cannot be empty."); } if (executionQueues.Any(x => x == null)) { throw new ArgumentOutOfRangeException("executionQueues", "Execution queues cannot contain null values."); } var queueTotalConcurrency = (byte)executionQueues.Sum(x => x.MaxConcurrency); _maxConcurrency = Math.Min(maxConcurrency, queueTotalConcurrency); _executionQueues = executionQueues.OrderByDescending(x => x.Priority).ToArray(); _executionInfos = new ExecutionInfo[_maxConcurrency]; _threadNames = Enumerable.Range(0, _maxConcurrency).Select(x => "DarkFlow#" + x).ToArray(); foreach (var executionQueue in executionQueues) { executionQueue.TaskAdded += OnTaskAdded; } Thread.MemoryBarrier(); }