Esempio n. 1
0
        private void ProcessQueue()
        {
            while (true)
            {
                var list = _queue.GetConsumingEnumerable(CancellationToken);

                if (MaxDegreeofParallelizm == 1)
                {
                    foreach (var item in list)
                    {
                        ProcessInternal(item);
                    }
                }
                else
                {
                    list.RunParallel()
                    .AsLongRunning()
                    .WithToken(CancellationToken)
                    .WithMaxDegreeofParallelizm(MaxDegreeofParallelizm)
                    .Run(ProcessInternal);
                }

                _queue = new BlockingPipe <TItem>(_queue.MaxCapacity);
                //   _queue = new BlockingCollection<TItem>(_queue.BoundedCapacity);
                _completeHandle.Set();
            }
        }
Esempio n. 2
0
        public ProcessingQueue(int boundedcapacity, CancellationToken token)
        {
            _queue = new BlockingPipe <TItem>(boundedcapacity);
            //_queue = new BlockingCollection<TItem>(boundedcapacity);

            _cancelSource = CancellationTokenSource.CreateLinkedTokenSource(token);

            _thread = new Thread(ProcessLoop)
            {
                IsBackground = true
            };
            _thread.Start();
        }