Exemplo n.º 1
0
        // Callback method must have the same signature as the
        // AsyncCallback delegate.
        public IQueueItem EndReceive(IAsyncResult asyncResult)
        {
            // Retrieve the delegate.
            ReceiveMessageCallback caller = (ReceiveMessageCallback)asyncResult.AsyncState;

            // Call EndInvoke to retrieve the results.
            IQueueItem item = (IQueueItem)caller.EndInvoke(asyncResult);

            AsyncCompleted(item);
            this.ResetEvent.WaitOne();
            return(item);
        }
Exemplo n.º 2
0
        public IQueueItem AsyncReceive(object state)
        {
            if (state == null)
            {
                state = new object();
            }
            TimeSpan timeout = TimeSpan.FromMilliseconds(QueueApi.LongTimeout);
            ReceiveMessageCallback caller = new ReceiveMessageCallback(this.ReceiveItemWorker);

            // Initiate the asychronous call.
            IAsyncResult result = caller.BeginInvoke(timeout, state, CreateCallBack(), caller);

            result.AsyncWaitHandle.WaitOne();

            // Call EndInvoke to wait for the asynchronous call to complete,
            // and to retrieve the results.
            IQueueItem item = caller.EndInvoke(result);

            AsyncCompleted(item);
            return(item);
        }