Exemple #1
0
        public ThreadCollection(SimpleThreadPoolSettings settings)
        {
            settings.Check();

            this.settings = settings;

            modificationSemaphore = new SemaphoreSlim(1, 1);

            workingThreads = new ConcurrentStack <WorkingThread>();
        }
        internal SimpleThreadPool(SimpleThreadPoolSettings settings, ThreadCollection threadCollection)
        {
            if (threadCollection == null)
            {
                throw new ArgumentException("threadCollection");
            }

            settings.Check();

            this.settings = settings;

            if (this.settings.MaxWorkingQueueCapacity == null)
            {
                blockingCollection = new BlockingCollection <IThreadPoolWorkItem>();
            }
            else
            {
                blockingCollection = new BlockingCollection <IThreadPoolWorkItem>(this.settings.MaxWorkingQueueCapacity.Value);
            }

            this.threadCollection = threadCollection;

            TryAddThreads(settings.StartWorkingThreadsCount);
        }