public IAsyncResult BeginReceive(TimeSpan timeout, object state, AsyncCallback callback) { long totalMilliseconds = (long)timeout.TotalMilliseconds; if ((totalMilliseconds < 0L) || (totalMilliseconds > 4294967295L)) { throw new ArgumentException("InvalidParameter", "timeout"); } ReceiveMessageCallback caller = new ReceiveMessageCallback(ReceiveItemWorker); if (callback == null) { callback = CreateCallBack(); } if (state == null) { state = new object(); } state = (int)ReceiveState.Wait; // Initiate the asychronous call. Include an AsyncCallback // delegate representing the callback method, and the data // needed to call EndInvoke. IAsyncResult result = caller.BeginInvoke(timeout, state, callback, caller); this.ResetEvent.Set(); //OnReceiveCompleted(new ReceiveResultEventArgs(this, result)); return(result); }
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); }