Example #1
0
        //--- Constructors ---

        /// <summary>
        /// Create an instance of the work queue.
        /// </summary>
        /// <param name="handler">Dispatch action for work item Type and with completion callback.</param>
        /// <param name="maxParallelism">Maximum number of items being dispatch simultaneously against the dispatch queue.</param>
        /// <param name="dispatchQueue">Dispatch queue for work items.</param>
        public ProcessingQueue(Action <T, Action> handler, int maxParallelism, IDispatchQueue dispatchQueue)
        {
            if (dispatchQueue == null)
            {
                throw new ArgumentNullException("dispatchQueue");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }
            if (maxParallelism <= 0)
            {
                throw new ArgumentException("maxParallelism must be greater than 0", "maxParallelism");
            }
            _handler       = handler;
            _capacity      = maxParallelism;
            _dispatchQueue = dispatchQueue;

            // check if we need an item holding queue
            if (maxParallelism < int.MaxValue)
            {
                _inbox = new LockFreeItemConsumerQueue <T>();
            }
        }