Esempio n. 1
0
        /// <summary>
        /// QueueAsyncProcessor constructor
        /// </summary>
        /// <param name="threadCount">Number of processing threads</param>
        /// <param name="queue">Processing queue (current instances of <see cref="QueueAsyncProcessor{T}"/> becomes the owner)</param>
        /// <param name="name">The name for this instance of <see cref="QueueAsyncProcessor{T}"/> and its threads</param>
        /// <param name="isBackground">Whether or not processing threads are background threads</param>
        public QueueAsyncProcessor(int threadCount, IQueue <T> queue, string name, bool isBackground)
        {
            if (threadCount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(threadCount), "Number of threads should be positive");
            }
            if (queue == null)
            {
                throw new ArgumentNullException(nameof(queue));
            }

            _isBackground = isBackground;
            _name         = name ?? this.GetType().GetCSName();

            _procThreads       = new Thread[threadCount];
            _activeThreadCount = 0;

            _queue         = queue;
            _blockingQueue = null; // Should work through interface only

            _stoppedEvent             = new ManualResetEventSlim(false);
            _stopRequestedCancelation = null;
            _stoppedCancelation       = null;

            _state            = (int)QueueAsyncProcessorState.Created;
            _completeAdding   = false;
            _letFinishProcess = false;

            Profiling.Profiler.QueueAsyncProcessorCreated(this.Name);
        }
Esempio n. 2
0
        /// <summary>
        /// QueueAsyncProcessor constructor
        /// </summary>
        /// <param name="threadCount">Number of processing threads</param>
        /// <param name="maxQueueSize">The bounded size of the queue (if less or equal to 0 then no limitation)</param>
        /// <param name="name">The name for this instance of <see cref="QueueAsyncProcessor{T}"/> and its threads</param>
        /// <param name="isBackground">Whether or not processing threads are background threads</param>
        public QueueAsyncProcessor(int threadCount, int maxQueueSize, string name, bool isBackground)
        {
            if (threadCount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(threadCount), "Number of threads should be positive");
            }

            _isBackground = isBackground;
            _name         = name ?? this.GetType().GetCSName();

            _procThreads       = new Thread[threadCount];
            _activeThreadCount = 0;

            _queue         = new MemoryQueue <T>(maxQueueSize > 0 ? maxQueueSize : -1);
            _blockingQueue = _queue as Collections.Concurrent.BlockingQueue <T>;

            _stoppedEvent             = new ManualResetEventSlim(false);
            _stopRequestedCancelation = null;
            _stoppedCancelation       = null;

            _state            = (int)QueueAsyncProcessorState.Created;
            _completeAdding   = false;
            _letFinishProcess = false;

            Profiling.Profiler.QueueAsyncProcessorCreated(this.Name);
        }