Esempio n. 1
0
        public bool Dequeue(TimeSpan timeout, out T value)
        {
            bool flag;

            InputQueue <T> .WaitQueueReader waitQueueReader = null;
            InputQueue <T> .Item            item            = new InputQueue <T> .Item();

            lock (this.ThisLock)
            {
                if (this.queueState == InputQueue <T> .QueueState.Open)
                {
                    if (!this.itemQueue.HasAvailableItem)
                    {
                        waitQueueReader = new InputQueue <T> .WaitQueueReader(this);

                        this.readerQueue.Enqueue(waitQueueReader);
                    }
                    else
                    {
                        item = this.itemQueue.DequeueAvailableItem();
                    }
                }
                else if (this.queueState != InputQueue <T> .QueueState.Shutdown)
                {
                    value = default(T);
                    flag  = true;
                    return(flag);
                }
                else if (this.itemQueue.HasAvailableItem)
                {
                    item = this.itemQueue.DequeueAvailableItem();
                }
                else if (!this.itemQueue.HasAnyItem)
                {
                    value = default(T);
                    flag  = true;
                    return(flag);
                }
                else
                {
                    waitQueueReader = new InputQueue <T> .WaitQueueReader(this);

                    this.readerQueue.Enqueue(waitQueueReader);
                }
                if (waitQueueReader != null)
                {
                    return(waitQueueReader.Wait(timeout, out value));
                }
                InputQueue <T> .InvokeDequeuedCallback(item.DequeuedCallback);

                value = item.GetValue();
                return(true);
            }
            return(flag);
        }
Esempio n. 2
0
        public IAsyncResult BeginDequeue(TimeSpan timeout, AsyncCallback callback, object state)
        {
            IAsyncResult asyncResult;

            InputQueue <T> .Item item = new InputQueue <T> .Item();

            lock (this.ThisLock)
            {
                if (this.queueState == InputQueue <T> .QueueState.Open)
                {
                    if (!this.itemQueue.HasAvailableItem)
                    {
                        InputQueue <T> .AsyncQueueReader asyncQueueReader = new InputQueue <T> .AsyncQueueReader(this, timeout, callback, state);

                        this.readerQueue.Enqueue(asyncQueueReader);
                        asyncResult = asyncQueueReader;
                        return(asyncResult);
                    }
                    else
                    {
                        item = this.itemQueue.DequeueAvailableItem();
                    }
                }
                else if (this.queueState == InputQueue <T> .QueueState.Shutdown)
                {
                    if (this.itemQueue.HasAvailableItem)
                    {
                        item = this.itemQueue.DequeueAvailableItem();
                    }
                    else if (this.itemQueue.HasAnyItem)
                    {
                        InputQueue <T> .AsyncQueueReader asyncQueueReader1 = new InputQueue <T> .AsyncQueueReader(this, timeout, callback, state);

                        this.readerQueue.Enqueue(asyncQueueReader1);
                        asyncResult = asyncQueueReader1;
                        return(asyncResult);
                    }
                }
                InputQueue <T> .InvokeDequeuedCallback(item.DequeuedCallback);

                return(new CompletedAsyncResult <T>(item.GetValue(), callback, state));
            }
            return(asyncResult);
        }