Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Issues with GetAllMessages method

174 views
Skip to first unread message

craig.b...@insight.com

unread,
Mar 18, 2011, 5:02:50 PM3/18/11
to
I recently started having an issue with the GetAllMessages method. I
have some logic that polls a remote message queue, looks for a
specific message on that queue, and then picks off the message when it
sees it arrive. The queue is remote to the machine this code is
running on (FormatName:DIRECT=OS:RemoteTestMachine\private$
\ResponseQueue).

Here is a code snippet:

readQueue.Refresh();

System.Messaging.Message[] allMessages =
readQueue.GetAllMessages();
foreach (System.Messaging.Message tMessage in allMessages)
{
try
{
//some logic here removed that verifies this is the message
we are waiting for

System.Messaging.Message thisMessage =
readQueue.ReceiveById(tMessage.Id);
response = (string)thisMessage.Body;
OutstandingMessages.Add(response);
}
catch (System.Messaging.MessageQueueException MessE)
{
TraceLogger.WriteLineIf(applicationSwitch.TraceError,
"Message Queue --> Error reading from message queue " + QueueName "
>>> [MessageQueueErrorCode=" + MessE.MessageQueueErrorCode + "]
[ErrorCode=" + MessE.ErrorCode + "]" + MessE.ToString());
if (MessE.InnerException != null)
TraceLogger.WriteLineIf(applicationSwitch.TraceError, "Message Queue --
> Error reading from message queue " + QueueName + " Inner Exception
>>> " + MessE.InnerException.ToString());
}
catch (Exception e)
{
TraceLogger.WriteLineIf(applicationSwitch.TraceError, "Message
Queue --> Error reading from message queue " + listener.QueueName + "
>>> " + e.ToString());
}
}

This code runs through the first time without errors. The expected
message is pulled off and everything works fine. The second time this
code executes, the call the GetAllMessages starts throwing the error
below. NOTE: MessageQueue.EnableConnectionCache is set to false.

Message Queue --> Error reading from message queue
FormatName:DIRECT=OS:RemoteTestMachine\private$\ResponseQueue
[MessageQueueErrorCode=-2147023170] [ErrorCode=-2147467259] >>>
System.Messaging.MessageQueueException
at System.Messaging.MessageEnumerator.get_CursorHandle()
at System.Messaging.MessageEnumerator.MoveNext(TimeSpan timeout)
at System.Messaging.MessageEnumerator.MoveNext()
at System.Messaging.MessageQueue.GetAllMessages()
at StartQueueListener()

There is no actual text associated with the exception, which seems
pretty strange. If anyone can point me in the right direction, it
will be much appreciated.

0 new messages