public bool EndTryReceive(IAsyncResult result, out Message message)
 {
     bool flag2;
     message = null;
     if (result == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("result");
     }
     DoneReceivingAsyncResult result2 = result as DoneReceivingAsyncResult;
     if (result2 != null)
     {
         return DoneReceivingAsyncResult.End(result2);
     }
     MsmqInputMessage msmqMessage = null;
     MsmqMessageProperty msmqProperty = null;
     try
     {
         bool flag = this.receiver.EndTryReceive(result, out msmqMessage, out msmqProperty);
         if (flag)
         {
             if (msmqProperty != null)
             {
                 message = this.DecodeMsmqMessage(msmqMessage, msmqProperty);
                 message.Properties["MsmqMessageProperty"] = msmqProperty;
                 if (this.receiveParameters.ReceiveContextSettings.Enabled)
                 {
                     message.Properties[ReceiveContext.Name] = this.receiveContextManager.CreateMsmqReceiveContext(msmqMessage.LookupId.Value);
                 }
                 MsmqDiagnostics.DatagramReceived(msmqMessage.MessageId, message);
                 this.listener.RaiseMessageReceived();
             }
             else if (CommunicationState.Opened == base.State)
             {
                 this.listener.FaultListener();
                 base.Fault();
             }
         }
         flag2 = flag;
     }
     catch (MsmqException exception)
     {
         if (exception.FaultReceiver)
         {
             this.listener.FaultListener();
             base.Fault();
         }
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception.Normalized);
     }
     finally
     {
         if (msmqMessage != null)
         {
             this.receiver.ReturnMessage(msmqMessage);
         }
     }
     return flag2;
 }
        // 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);
                }
            }
        }
        public bool EndTryReceive(IAsyncResult result, out Message message)
        {
            message = null;

            if (null == result)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("result");
            }

            DoneReceivingAsyncResult doneRecevingResult = result as DoneReceivingAsyncResult;

            if (doneRecevingResult != null)
            {
                return(DoneReceivingAsyncResult.End(doneRecevingResult));
            }

            MsmqInputMessage    msmqMessage = null;
            MsmqMessageProperty property    = null;

            try
            {
                bool retval = this.receiver.EndTryReceive(result, out msmqMessage, 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
            {
                if (null != msmqMessage)
                {
                    this.receiver.ReturnMessage(msmqMessage);
                }
            }
        }