예제 #1
0
        public IAsyncResult BeginWaitForItem(TimeSpan timeout, AsyncCallback callback, object state)
        {
            lock (ThisLock)
            {
                if (_queueState == QueueState.Open)
                {
                    if (!_itemQueue.HasAvailableItem)
                    {
                        var waiter = new AsyncQueueWaiter(timeout, callback, state);
                        _waiterList.Add(waiter);
                        return(waiter);
                    }
                }
                else if (_queueState == QueueState.Shutdown)
                {
                    if (!_itemQueue.HasAvailableItem && _itemQueue.HasAnyItem)
                    {
                        var waiter = new AsyncQueueWaiter(timeout, callback, state);
                        _waiterList.Add(waiter);
                        return(waiter);
                    }
                }
            }

            return(new TypedCompletedAsyncResult <bool>(true, callback, state));
        }
예제 #2
0
        public bool EndWaitForItem(IAsyncResult result)
        {
            var typedResult = result as TypedCompletedAsyncResult <bool>;

            if (typedResult != null)
            {
                return(TypedCompletedAsyncResult <bool> .End(result));
            }

            return(AsyncQueueWaiter.End(result));
        }