protected override void OnEnqueueItem(AsyncQueueItemBase item, AsyncQueuePriority priority, string itemKey)
 {
     _queue.Enqueue(item);
 }
Exemple #2
0
        private void DequeueItems(object notUsed)
        {
            if (Interlocked.Decrement(ref _EnqueueThreads) > 0)
            {
                // another thread following - exit
                return;
            }

            bool checkDone;
            long threadCount = 0;

            do
            {
                checkDone   = false;
                threadCount = Interlocked.Increment(ref _DequeueThreads);
                try
                {
                    if (threadCount == 1)
                    {
                        // we are the dequeue thread - dequeue all items
                        checkDone = true;
                        long queueLength;
                        //new
                        AcquireLock();
                        try
                        {
                            queueLength = this.OnGetQueueLength();
                            while (queueLength > 0)
                            {
                                AsyncQueueItemBase item = this.OnDequeueItem();
                                ReleaseLock();
                                try
                                {
                                    if (item != null)
                                    {
                                        // process item
                                        // - or discard it if closed
                                        if (!_Closed)
                                        {
                                            try
                                            {
                                                item.CallUserCallback();
                                            }
                                            catch (Exception e)
                                            {
                                                if (_Logger != null)
                                                {
                                                    _Logger.Log(e);
                                                }
                                                else
                                                {
                                                    Debug.WriteLine("AsyncQueueBase: " + e.ToString());
                                                }
                                            }
                                        }
                                    }
                                }
                                finally
                                {
                                    AcquireLock();
                                }
                                // next
                                queueLength = this.OnGetQueueLength();
                            }
                        }
                        finally
                        {
                            ReleaseLock();
                        }
                    }
                }
                finally
                {
                    threadCount = Interlocked.Decrement(ref _DequeueThreads);
                }
            } while ((threadCount == 0) && (!checkDone));
        }
Exemple #3
0
 protected virtual void OnEnqueueItem(AsyncQueueItemBase item, AsyncQueuePriority priority, string itemKey)
 {
     throw new NotImplementedException();
 }
Exemple #4
0
 protected override void OnEnqueueItem(AsyncQueueItemBase item, AsyncQueuePriority priority, string itemKey)
 {
     _PriorityStack[(int)priority][itemKey] = item;
 }