Ejemplo n.º 1
0
        public ThreadPoolHandler StartPool(ThreadPoolOptions threadPoolOptions)
        {
            ThreadPoolHandler threadPoolHandler = this.CreatePool(threadPoolOptions);

            foreach (var job in threadPoolOptions.Jobs)
            {
                threadPoolHandler.addJob(job);
            }

            threadPoolHandler.Start();
            return(threadPoolHandler);
        }
Ejemplo n.º 2
0
        public ThreadPoolHandler CreatePool(ThreadPoolOptions threadPoolOptions)
        {
            ThreadPoolHandler handler = new ThreadPoolHandler(threadPoolOptions);
            ThreadPoolHandler result  = null;

            if (!_pool.ContainsKey(handler.PoolName))
            {
                if (_pool.TryAdd(handler.PoolName, handler))
                {
                    result = handler;
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public ThreadPoolHandler(ThreadPoolOptions threadPoolOptions)
        {
            if (threadPoolOptions == null)
            {
                threadPoolOptions = new ThreadPoolOptions()
                {
                };
            }
            Interlocked.Increment(ref poolNumber);
            string poolName = "ThreadPool-" + poolNumber;

            _waitCallback = threadPoolOptions.TargetMethod;
            _jobQueue     = Queue.Synchronized(new Queue());
            _poolName     = threadPoolOptions.PoolName ?? poolName;
            _poolSize     = threadPoolOptions.PoolSize ?? throw new ArgumentException("PoolSize is required parameter");
            _exitOnFinish = threadPoolOptions.ExitOnFinish ?? true;
        }