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); }
private static void CompleteWaitersTrueCallback(object state) { InputQueue <T> .CompleteWaiters(true, (InputQueue <T> .IQueueWaiter[]) state); }