private void CollectLocks(MsmqQueue lockQueue)
        {
            ReceiveResult result = ReceiveResult.MessageReceived;

            while (result == ReceiveResult.MessageReceived)
            {
                using (MsmqMessageLookupId message = new MsmqMessageLookupId())
                {
                    try
                    {
                        result = lockQueue.TryPeek(message, TimeSpan.FromSeconds(0));
                        if (result == ReceiveResult.MessageReceived)
                        {
                            lockQueue.TryMoveMessage(message.lookupId.Value, this.mainQueueForMove, MsmqTransactionMode.None);
                        }
                    }
                    catch (MsmqException ex)
                    {
                        // we will retry the collection in the next cleanup round
                        MsmqDiagnostics.ExpectedException(ex);
                        result = ReceiveResult.Unknown;
                    }
                }
            }
        }
Beispiel #2
0
        public override MsmqQueue.ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode)
        {
            MsmqQueue.MoveReceiveResult result3;
            TimeoutHelper helper   = new TimeoutHelper(timeout);
            bool          flag     = false;
            long          lookupId = 0L;

            while (!flag)
            {
                using (MsmqMessageLookupId id = new MsmqMessageLookupId())
                {
                    MsmqQueue.ReceiveResult result = base.TryPeek(id, helper.RemainingTime());
                    if (result != MsmqQueue.ReceiveResult.MessageReceived)
                    {
                        return(result);
                    }
                    lookupId = id.lookupId.Value;
                }
                try
                {
                    if (base.TryMoveMessage(lookupId, this.lockQueueForMove, MsmqTransactionMode.None) == MsmqQueue.MoveReceiveResult.Succeeded)
                    {
                        flag = true;
                    }
                    continue;
                }
                catch (MsmqException exception)
                {
                    MsmqDiagnostics.ExpectedException(exception);
                    continue;
                }
            }
            try
            {
                result3 = this.lockQueueForReceive.TryReceiveByLookupId(lookupId, message, MsmqTransactionMode.None, 0x40000010);
            }
            catch (MsmqException exception2)
            {
                this.UnlockMessage(lookupId, TimeSpan.Zero);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception2);
            }
            if (result3 == MsmqQueue.MoveReceiveResult.Succeeded)
            {
                return(MsmqQueue.ReceiveResult.MessageReceived);
            }
            this.UnlockMessage(lookupId, TimeSpan.Zero);
            return(MsmqQueue.ReceiveResult.OperationCancelled);
        }
 private void CollectLocks(MsmqQueue lockQueue)
 {
     MsmqQueue.ReceiveResult messageReceived = MsmqQueue.ReceiveResult.MessageReceived;
     while (messageReceived == MsmqQueue.ReceiveResult.MessageReceived)
     {
         using (MsmqMessageLookupId id = new MsmqMessageLookupId())
         {
             try
             {
                 messageReceived = lockQueue.TryPeek(id, TimeSpan.FromSeconds(0.0));
                 if (messageReceived == MsmqQueue.ReceiveResult.MessageReceived)
                 {
                     lockQueue.TryMoveMessage(id.lookupId.Value, this.mainQueueForMove, MsmqTransactionMode.None);
                 }
             }
             catch (MsmqException exception)
             {
                 MsmqDiagnostics.ExpectedException(exception);
                 messageReceived = MsmqQueue.ReceiveResult.Unknown;
             }
             continue;
         }
     }
 }
Beispiel #4
0
 private void CollectLocks(MsmqQueue lockQueue)
 {
     MsmqQueue.ReceiveResult messageReceived = MsmqQueue.ReceiveResult.MessageReceived;
     while (messageReceived == MsmqQueue.ReceiveResult.MessageReceived)
     {
         using (MsmqMessageLookupId id = new MsmqMessageLookupId())
         {
             try
             {
                 messageReceived = lockQueue.TryPeek(id, TimeSpan.FromSeconds(0.0));
                 if (messageReceived == MsmqQueue.ReceiveResult.MessageReceived)
                 {
                     lockQueue.TryMoveMessage(id.lookupId.Value, this.mainQueueForMove, MsmqTransactionMode.None);
                 }
             }
             catch (MsmqException exception)
             {
                 MsmqDiagnostics.ExpectedException(exception);
                 messageReceived = MsmqQueue.ReceiveResult.Unknown;
             }
             continue;
         }
     }
 }
        public override ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode)
        {
            // we ignore transaction mode for receive context receives
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            bool receivedMessage = false;
            long lookupId        = 0;

            // peek for new message, move it to the lock queue and then receive the full message
            // if move fails because another thread moved it ahead of us then peek again
            while (!receivedMessage)
            {
                ReceiveResult     result;
                MoveReceiveResult moveResult;

                using (MsmqMessageLookupId emptyMessage = new MsmqMessageLookupId())
                {
                    result = this.TryPeek(emptyMessage, timeoutHelper.RemainingTime());
                    if (result != ReceiveResult.MessageReceived)
                    {
                        return(result);
                    }
                    lookupId = emptyMessage.lookupId.Value;
                }

                try
                {
                    moveResult = this.TryMoveMessage(lookupId, this.lockQueueForMove, MsmqTransactionMode.None);
                    if (moveResult == MoveReceiveResult.Succeeded)
                    {
                        receivedMessage = true;
                    }
                }
                catch (MsmqException ex)
                {
                    MsmqDiagnostics.ExpectedException(ex);
                }
            }

            MoveReceiveResult lookupIdReceiveResult;

            try
            {
                lookupIdReceiveResult = this.lockQueueForReceive.TryReceiveByLookupId(lookupId, message, MsmqTransactionMode.None, UnsafeNativeMethods.MQ_LOOKUP_PEEK_CURRENT);
            }
            catch (MsmqException ex)
            {
                this.UnlockMessage(lookupId, TimeSpan.Zero);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex);
            }

            if (lookupIdReceiveResult == MoveReceiveResult.Succeeded)
            {
                return(ReceiveResult.MessageReceived);
            }
            else
            {
                this.UnlockMessage(lookupId, TimeSpan.Zero);
                return(ReceiveResult.OperationCancelled);
            }
        }
 public override MsmqQueue.ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode)
 {
     MsmqQueue.MoveReceiveResult result3;
     TimeoutHelper helper = new TimeoutHelper(timeout);
     bool flag = false;
     long lookupId = 0L;
     while (!flag)
     {
         using (MsmqMessageLookupId id = new MsmqMessageLookupId())
         {
             MsmqQueue.ReceiveResult result = base.TryPeek(id, helper.RemainingTime());
             if (result != MsmqQueue.ReceiveResult.MessageReceived)
             {
                 return result;
             }
             lookupId = id.lookupId.Value;
         }
         try
         {
             if (base.TryMoveMessage(lookupId, this.lockQueueForMove, MsmqTransactionMode.None) == MsmqQueue.MoveReceiveResult.Succeeded)
             {
                 flag = true;
             }
             continue;
         }
         catch (MsmqException exception)
         {
             MsmqDiagnostics.ExpectedException(exception);
             continue;
         }
     }
     try
     {
         result3 = this.lockQueueForReceive.TryReceiveByLookupId(lookupId, message, MsmqTransactionMode.None, 0x40000010);
     }
     catch (MsmqException exception2)
     {
         this.UnlockMessage(lookupId, TimeSpan.Zero);
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception2);
     }
     if (result3 == MsmqQueue.MoveReceiveResult.Succeeded)
     {
         return MsmqQueue.ReceiveResult.MessageReceived;
     }
     this.UnlockMessage(lookupId, TimeSpan.Zero);
     return MsmqQueue.ReceiveResult.OperationCancelled;
 }
        private void CollectLocks(MsmqQueue lockQueue)
        {
            ReceiveResult result = ReceiveResult.MessageReceived;

            while (result == ReceiveResult.MessageReceived)
            {
                using (MsmqMessageLookupId message = new MsmqMessageLookupId())
                {
                    try
                    {
                        result = lockQueue.TryPeek(message, TimeSpan.FromSeconds(0));
                        if (result == ReceiveResult.MessageReceived)
                        {
                            lockQueue.TryMoveMessage(message.lookupId.Value, this.mainQueueForMove, MsmqTransactionMode.None);
                        }
                    }
                    catch (MsmqException ex)
                    {
                        // we will retry the collection in the next cleanup round
                        MsmqDiagnostics.ExpectedException(ex);
                        result = ReceiveResult.Unknown;
                    }
                }
            }
        }
        public override ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode)
        {
            // we ignore transaction mode for receive context receives
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            bool receivedMessage = false;
            long lookupId = 0;

            // peek for new message, move it to the lock queue and then receive the full message
            // if move fails because another thread moved it ahead of us then peek again
            while (!receivedMessage)
            {
                ReceiveResult result;
                MoveReceiveResult moveResult;

                using (MsmqMessageLookupId emptyMessage = new MsmqMessageLookupId())
                {
                    result = this.TryPeek(emptyMessage, timeoutHelper.RemainingTime());
                    if (result != ReceiveResult.MessageReceived)
                    {
                        return result;
                    }
                    lookupId = emptyMessage.lookupId.Value;
                }

                try
                {
                    moveResult = this.TryMoveMessage(lookupId, this.lockQueueForMove, MsmqTransactionMode.None);
                    if (moveResult == MoveReceiveResult.Succeeded)
                    {
                        receivedMessage = true;
                    }
                }
                catch (MsmqException ex)
                {
                    MsmqDiagnostics.ExpectedException(ex);
                }
            }

            MoveReceiveResult lookupIdReceiveResult;
            try
            {
                lookupIdReceiveResult = this.lockQueueForReceive.TryReceiveByLookupId(lookupId, message, MsmqTransactionMode.None, UnsafeNativeMethods.MQ_LOOKUP_PEEK_CURRENT);
            }
            catch (MsmqException ex)
            {
                this.UnlockMessage(lookupId, TimeSpan.Zero);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex);
            }

            if (lookupIdReceiveResult == MoveReceiveResult.Succeeded)
            {
                return ReceiveResult.MessageReceived;
            }
            else
            {
                this.UnlockMessage(lookupId, TimeSpan.Zero);
                return ReceiveResult.OperationCancelled;
            }
        }