public IAsyncResult BeginReceive(TimeSpan timeout, AsyncCallback callback, object state) { using (MsmqDiagnostics.BoundReceiveOperation(this.receiver)) { return(InputChannel.HelpBeginReceive(this, timeout, callback, state)); } }
// TryReceive public bool TryReceive(TimeSpan timeout, out Message message) { message = null; if (DoneReceivingInCurrentState()) { return(true); } using (MsmqDiagnostics.BoundReceiveOperation(this.receiver)) { MsmqInputMessage msmqMessage = this.receiver.TakeMessage(); try { MsmqMessageProperty property; bool retval = this.receiver.TryReceive( msmqMessage, timeout, this.ReceiveParameters.ExactlyOnce ? MsmqTransactionMode.CurrentOrNone : MsmqTransactionMode.None, out property); if (retval) { if (null != property) { message = DecodeMsmqMessage(msmqMessage, property); message.Properties[MsmqMessageProperty.Name] = property; if (this.receiveParameters.ReceiveContextSettings.Enabled) { message.Properties[MsmqReceiveContext.Name] = this.receiveContextManager.CreateMsmqReceiveContext(msmqMessage.LookupId.Value); } MsmqDiagnostics.DatagramReceived(msmqMessage.MessageId, message); this.listener.RaiseMessageReceived(); } else if (CommunicationState.Opened == this.State) { this.listener.FaultListener(); this.Fault(); } } return(retval); } catch (MsmqException ex) { if (ex.FaultReceiver) { this.listener.FaultListener(); this.Fault(); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex.Normalized); } finally { this.receiver.ReturnMessage(msmqMessage); } } }