コード例 #1
0
 protected override void OnEnqueueItem(AsyncQueueItemBase item, AsyncQueuePriority priority, string itemKey)
 {
     _queue.Enqueue(item);
 }
コード例 #2
0
 protected virtual void OnEnqueueItem(AsyncQueueItemBase item, AsyncQueuePriority priority, string itemKey)
 {
     throw new NotImplementedException();
 }
コード例 #3
0
 protected override void OnEnqueueItem(AsyncQueueItemBase item, AsyncQueuePriority priority, string itemKey)
 {
     _priorityStack[(int)priority][itemKey] = item;
 }
コード例 #4
0
        private void DequeueItems(object notUsed)
        {
            if (Interlocked.Decrement(ref _enqueueThreads) > 0)
            {
                // another thread following - exit
                return;
            }

            bool checkDone;
            long threadCount;

            do
            {
                checkDone   = false;
                threadCount = Interlocked.Increment(ref _dequeueThreads);
                try
                {
                    if (threadCount == 1)
                    {
                        // we are the dequeue thread - dequeue all items
                        checkDone = true;
                        //new
                        AcquireLock();
                        try
                        {
                            var queueLength = OnGetQueueLength();
                            while (queueLength > 0)
                            {
                                AsyncQueueItemBase item = 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);
                                                }
                                            }
                                        }
                                    }
                                }
                                finally
                                {
                                    AcquireLock();
                                }
                                // next
                                queueLength = OnGetQueueLength();
                            }
                        }
                        finally
                        {
                            ReleaseLock();
                        }
                    }
                }
                finally
                {
                    threadCount = Interlocked.Decrement(ref _dequeueThreads);
                }
            } while ((threadCount == 0) && (!checkDone));
        }