private void AsyncReadMessage(object state) { ReadMessageAsyncResult ar = (ReadMessageAsyncResult)state; try { PmlElement message = ReadMessage(); ar.SetCompleted(false, null, message); } catch (Exception ex) { ar.SetCompleted(false, ex, null); } }
public IAsyncResult BeginReadMessage(AsyncCallback callback, object state) { ReadMessageAsyncResult ar; Boolean completed = false; lock (_queue) { if (!IsOpen) { throw new InvalidOperationException("The channel is not open"); } if (_asyncWait != null) { throw new InvalidOperationException("Another asynchronous operation is in progress"); } ar = new ReadMessageAsyncResult(callback, state); if (_queue.Count == 0) { _asyncWait = ar; } else { ar.Message = _queue.Dequeue(); completed = true; } } if (completed) { ar.SetCompleted(true, null); } return(ar); }