Jellyfish.Commands.BulkheadTaskScheduler.BulkheadTaskScheduler C# (CSharp) Method

BulkheadTaskScheduler() public method

Initializes the scheduler.
public BulkheadTaskScheduler ( int threadCount, string threadName ) : System
threadCount int The number of threads to create and use for processing work items.
threadName string The name to use for each of the created threads.
return System
        public BulkheadTaskScheduler(
            int threadCount,
            string threadName)
        {
            // Validates arguments (some validation is left up to the Thread type itself). 
            // If the thread count is 0, default to the number of logical processors. 
            if (threadCount < 0) throw new ArgumentOutOfRangeException("concurrencyLevel");
            else if (threadCount == 0) _concurrencyLevel = Environment.ProcessorCount;
            else _concurrencyLevel = threadCount;

            // Initialize the queue used for storing tasks 
            _blockingTaskQueue = new BlockingCollection<Task>(threadCount);

            // Create all of the threads 
            _threads = new Thread[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                _threads[i] = new Thread(() => ThreadBasedDispatchLoop());
                if (threadName != null) _threads[i].Name = "jellyfish-" + threadName + " (" + i + ")";
            }

            // Start all of the threads 
            foreach (var thread in _threads) thread.Start();
        }