Ejemplo n.º 1
0
        private void EnqueueAndDispatch(Item item, bool canDispatchOnThisThread)
        {
            bool         disposeItem   = false;
            IQueueReader reader        = null;
            bool         dispatchLater = false;

            IQueueWaiter[] waiters       = null;
            bool           itemAvailable = true;

            lock (ThisLock)
            {
                itemAvailable = !((_queueState == QueueState.Closed) || (_queueState == QueueState.Shutdown));
                this.GetWaiters(out waiters);

                if (_queueState == QueueState.Open)
                {
                    if (canDispatchOnThisThread)
                    {
                        if (_readerQueue.Count == 0)
                        {
                            _itemQueue.EnqueueAvailableItem(item);
                        }
                        else
                        {
                            reader = _readerQueue.Dequeue();
                        }
                    }
                    else
                    {
                        if (_readerQueue.Count == 0)
                        {
                            _itemQueue.EnqueueAvailableItem(item);
                        }
                        else
                        {
                            _itemQueue.EnqueuePendingItem(item);
                            dispatchLater = true;
                        }
                    }
                }
                else // queueState == QueueState.Closed || queueState == QueueState.Shutdown
                {
                    disposeItem = true;
                }
            }

            if (waiters != null)
            {
                if (canDispatchOnThisThread)
                {
                    CompleteWaiters(itemAvailable, waiters);
                }
                else
                {
                    CompleteWaitersLater(itemAvailable, waiters);
                }
            }

            if (reader != null)
            {
                InvokeDequeuedCallback(item.DequeuedCallback);
                reader.Set(item);
            }

            if (dispatchLater)
            {
                if (s_onDispatchCallback == null)
                {
                    s_onDispatchCallback = new Action <object>(OnDispatchCallback);
                }

                ActionItem.Schedule(s_onDispatchCallback, this);
            }
            else if (disposeItem)
            {
                InvokeDequeuedCallback(item.DequeuedCallback);
                DisposeItem(item);
            }
        }
Ejemplo n.º 2
0
 private void ScheduleWait()
 {
     ActionItem.Schedule(onWaitCallback, null);
     waitScheduled = true;
 }
 protected void Schedule()
 {
     ActionItem.Schedule(ScheduleActionItemAsyncResult.doWork, this);
 }
Ejemplo n.º 4
0
 void ScheduleWait()
 {
     ActionItem.Schedule(this.onWaitCallback, null);
     this.waitScheduled = true;
 }
Ejemplo n.º 5
0
 public static void Schedule(Action <object> callback, object state)
 {
     ActionItem.Schedule(callback, state, false);
 }
Ejemplo n.º 6
0
 private void ScheduleCallback(Action <object> callback)
 {
     ActionItem.ScheduleCallback(callback, this, this.lowPriority);
 }
Ejemplo n.º 7
0
        private void EnqueueAndDispatch(InputQueue <T> .Item item, bool canDispatchOnThisThread)
        {
            bool flag = false;
            bool flag1;
            bool flag2 = false;

            InputQueue <T> .IQueueReader queueReader = null;
            bool flag3 = false;

            InputQueue <T> .IQueueWaiter[] queueWaiterArray = null;
            lock (this.ThisLock)
            {
                if (this.queueState == InputQueue <T> .QueueState.Closed)
                {
                    flag1 = false;
                }
                else
                {
                    flag1 = this.queueState != InputQueue <T> .QueueState.Shutdown;
                }
                this.GetWaiters(out queueWaiterArray);
                if (this.queueState != InputQueue <T> .QueueState.Open)
                {
                }
                else
                {
                    if (!canDispatchOnThisThread)
                    {
                        if (this.readerQueue.Count != 0)
                        {
                            this.itemQueue.EnqueuePendingItem(item);
                        }
                        else
                        {
                            this.itemQueue.EnqueueAvailableItem(item);
                        }
                    }
                    else
                    {
                        if (this.readerQueue.Count != 0)
                        {
                            queueReader = this.readerQueue.Dequeue();
                        }
                        else
                        {
                            this.itemQueue.EnqueueAvailableItem(item);
                        }
                    }
                }
            }
            if (queueWaiterArray != null)
            {
                if (!canDispatchOnThisThread)
                {
                    InputQueue <T> .CompleteWaitersLater(flag, queueWaiterArray);
                }
                else
                {
                    InputQueue <T> .CompleteWaiters(flag, queueWaiterArray);
                }
            }
            if (queueReader != null)
            {
                InputQueue <T> .InvokeDequeuedCallback(item.DequeuedCallback);

                queueReader.Set(item);
            }
            if (!flag3)
            {
                if (flag2)
                {
                    InputQueue <T> .InvokeDequeuedCallback(item.DequeuedCallback);

                    this.DisposeItem(item);
                }
                return;
            }
            else
            {
                if (InputQueue <T> .onDispatchCallback == null)
                {
                    InputQueue <T> .onDispatchCallback = new Action <object>(InputQueue <T> .OnDispatchCallback);
                }
                ActionItem.Schedule(InputQueue <T> .onDispatchCallback, this);
                return;
            }
        }
 protected void Schedule()
 {
     ActionItem.Schedule(doWork, this);
 }
Ejemplo n.º 9
0
        private void EnqueueAndDispatch(Item <T> item, bool canDispatchOnThisThread)
        {
            bool             flag   = false;
            IQueueReader <T> reader = null;
            bool             flag2  = false;

            IQueueWaiter <T>[] waiters = null;
            bool itemAvailable         = true;

            lock (this.ThisLock)
            {
                itemAvailable = (this.queueState != QueueState <T> .Closed) && (this.queueState != QueueState <T> .Shutdown);
                this.GetWaiters(out waiters);
                if (this.queueState == QueueState <T> .Open)
                {
                    if (canDispatchOnThisThread)
                    {
                        if (this.readerQueue.Count == 0)
                        {
                            this.itemQueue.EnqueueAvailableItem(item);
                        }
                        else
                        {
                            reader = this.readerQueue.Dequeue();
                        }
                    }
                    else if (this.readerQueue.Count == 0)
                    {
                        this.itemQueue.EnqueueAvailableItem(item);
                    }
                    else
                    {
                        this.itemQueue.EnqueuePendingItem(item);
                        flag2 = true;
                    }
                }
                else
                {
                    flag = true;
                }
            }
            if (waiters != null)
            {
                if (canDispatchOnThisThread)
                {
                    InputQueue <T> .CompleteWaiters(itemAvailable, waiters);
                }
                else
                {
                    InputQueue <T> .CompleteWaitersLater(itemAvailable, waiters);
                }
            }
            if (reader != null)
            {
                InputQueue <T> .InvokeDequeuedCallback(item.DequeuedCallback);

                reader.Set(item);
            }
            if (flag2)
            {
                if (InputQueue <T> .onDispatchCallback == null)
                {
                    InputQueue <T> .onDispatchCallback = new Action <object>(InputQueue <T> .OnDispatchCallback);
                }
                ActionItem.Schedule(InputQueue <T> .onDispatchCallback, this);
            }
            else if (flag)
            {
                InputQueue <T> .InvokeDequeuedCallback(item.DequeuedCallback);

                this.DisposeItem(item);
            }
        }