Example #1
0
        private bool TryDequeue(out EnqueuedTask task)
        {
            Lock.EnterWriteLock();
            try
            {
                if (Queue.Count() != 0)
                {
                    task = Queue.Dequeue();
                    return(true);
                }

                task = null;
                return(false);
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }
Example #2
0
        public EnqueuedTask Enqueue(double priority, Action action)
        {
            Lock.EnterWriteLock();
            try
            {
                EnqueuedTask task = new EnqueuedTask(this, priority, action, Guid.NewGuid());

                Queue.Enqueue(task);

                if (Interlocked.Read(ref _workerCount) < MaxConcurrent)
                {
                    Interlocked.Increment(ref _workerCount);
                    _threadPool.QueueUserWorkItem(Worker);
                }

                return(task);
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }