Esempio n. 1
0
 private void ScheduleCallback(Action <object> callback)
 {
     ActionItem.ScheduleCallback(callback, this, this.lowPriority);
 }
Esempio n. 2
0
 public static void Schedule(Action <object> callback, object state)
 {
     ActionItem.Schedule(callback, state, false);
 }
Esempio n. 3
0
        private void EnqueueAndDispatch(InputQueue <T> .Item item, bool canDispatchOnThisThread)
        {
            bool flag = false;

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

            InputQueue <T> .IQueueWaiter[] queueWaiterArray = null;
            bool flag2 = true;

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

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

                    this.DisposeItem(item);
                }
                return;
            }
            if (InputQueue <T> .onDispatchCallback == null)
            {
                InputQueue <T> .onDispatchCallback = new Action <object>(InputQueue <T> .OnDispatchCallback);
            }
            ActionItem.Schedule(InputQueue <T> .onDispatchCallback, this);
        }
Esempio n. 4
0
 void ScheduleWait()
 {
     ActionItem.Schedule(this.onWaitCallback, null);
     this.waitScheduled = true;
 }
Esempio n. 5
0
        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 (onDispatchCallback == null)
                {
                    onDispatchCallback = new Action <object>(OnDispatchCallback);
                }

                ActionItem.Schedule(onDispatchCallback, this);
            }
            else if (disposeItem)
            {
                InvokeDequeuedCallback(item.DequeuedCallback);
                DisposeItem(item);
            }
        }