public void Dispatch() { InputQueue <T> .IQueueReader queueReader = null; InputQueue <T> .Item item = new InputQueue <T> .Item(); InputQueue <T> .IQueueReader[] queueReaderArray = null; InputQueue <T> .IQueueWaiter[] queueWaiterArray = null; bool flag = true; lock (this.ThisLock) { flag = (this.queueState == InputQueue <T> .QueueState.Closed ? false : this.queueState != InputQueue <T> .QueueState.Shutdown); this.GetWaiters(out queueWaiterArray); if (this.queueState != InputQueue <T> .QueueState.Closed) { this.itemQueue.MakePendingItemAvailable(); if (this.readerQueue.Count > 0) { item = this.itemQueue.DequeueAvailableItem(); queueReader = this.readerQueue.Dequeue(); if (this.queueState == InputQueue <T> .QueueState.Shutdown && this.readerQueue.Count > 0 && this.itemQueue.ItemCount == 0) { queueReaderArray = new InputQueue <T> .IQueueReader[this.readerQueue.Count]; this.readerQueue.CopyTo(queueReaderArray, 0); this.readerQueue.Clear(); flag = false; } } } } if (queueReaderArray != null) { if (InputQueue <T> .completeOutstandingReadersCallback == null) { InputQueue <T> .completeOutstandingReadersCallback = new Action <object>(InputQueue <T> .CompleteOutstandingReadersCallback); } ActionItem.Schedule(InputQueue <T> .completeOutstandingReadersCallback, queueReaderArray); } if (queueWaiterArray != null) { InputQueue <T> .CompleteWaitersLater(flag, queueWaiterArray); } if (queueReader != null) { InputQueue <T> .InvokeDequeuedCallback(item.DequeuedCallback); queueReader.Set(item); } }
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); }