Ejemplo n.º 1
0
        public bool EndDequeue(IAsyncResult result, out T value)
        {
            var typedResult = result as TypedCompletedAsyncResult <T>;

            if (typedResult != null)
            {
                value = TypedCompletedAsyncResult <T> .End(result);

                return(true);
            }

            return(AsyncQueueReader <T> .End(result, out value));
        }
Ejemplo n.º 2
0
        public IAsyncResult BeginDequeue(TimeSpan timeout, AsyncCallback callback, object state)
        {
            var item = default(Item <T>);

            lock (ThisLock)
            {
                if (_queueState == QueueState.Open)
                {
                    if (_itemQueue.HasAvailableItem)
                    {
                        item = _itemQueue.DequeueAvailableItem();
                    }
                    else
                    {
                        var reader = new AsyncQueueReader <T>(this, timeout, callback, state);
                        _readerQueue.Enqueue(reader);
                        return(reader);
                    }
                }
                else if (_queueState == QueueState.Shutdown)
                {
                    if (_itemQueue.HasAvailableItem)
                    {
                        item = _itemQueue.DequeueAvailableItem();
                    }
                    else if (_itemQueue.HasAnyItem)
                    {
                        var reader = new AsyncQueueReader <T>(this, timeout, callback, state);
                        _readerQueue.Enqueue(reader);
                        return(reader);
                    }
                }
            }

            InvokeDequeuedCallback(item.DequeuedCallback);
            return(new TypedCompletedAsyncResult <T>(item.GetValue(), callback, state));
        }