Пример #1
0
        /// <summary>
        /// Создаёт пул в соответствии с настройками
        /// </summary>
        /// <returns>Новый пул</returns>
        public ISimpleThreadPool Create()
        {
            var threadCollection = new ThreadCollection(Settings);
            var result           = new SimpleThreadPool(Settings, threadCollection);

            var strategies = PerformanceBalanceSettings.PerformanceBalancerStrategies ?? new List <IPerformanceBalancerStrategy>();

            if (strategies.Count > 0)
            {
                var balancer = new PerformanceBalancer(result, result, PerformanceBalanceSettings);
                result.SetPerformanceBalancer(balancer, PerformanceBalanceSettings);
            }

            return(result);
        }
Пример #2
0
        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);
        }