Пример #1
0
        /// <summary>Completes the specified asynchronous receive operation.</summary>
        /// <param name="asyncResult"></param>
        /// <returns></returns>
        public IQueueItem EndReceive(IAsyncResult asyncResult)
        {
            // Retrieve the delegate.
            ReceiveItemCallback caller = (ReceiveItemCallback)asyncResult.AsyncState;

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

            AsyncCompleted(item);
            this.resetEvent.WaitOne();
            return(item);
        }
Пример #2
0
        /// <summary>
        /// AsyncReceive
        /// </summary>
        /// <returns></returns>
        public IQueueItem AsyncReceive()
        {
            object   state = new object();
            TimeSpan ts    = TimeSpan.FromSeconds(QueueDefaults.DefaultRecieveTimeOutInSecond);

            ReceiveItemCallback caller = new ReceiveItemCallback(ReceiveItemWorker);

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

            Thread.Sleep(10);

            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);
        }