question about MessageQueue

C

Charles Shao

question about MessageQueue

Hi, friends:

I try to send a message into MSMQ and then read it out.
But I find the message is not be removed after being accessed.
How can I read and remove it ?

Thanks

Charles Shao
================================================================
myNewPrivateQueue1.Send("My message data.",
MessageQueueTransactionType.Single);
MessageEnumerator myEnumerator =
myNewPrivateQueue1.GetMessageEnumerator();

// Specify that the messages's priority should be read.
myNewPrivateQueue1.MessageReadPropertyFilter.Priority = true;

// Move to the next message and examine its priority.
while(myEnumerator.MoveNext())
{
// Increase the count if priority is Lowest.
if(myEnumerator.Current.Priority ==
MessagePriority.Lowest)

Console.WriteLine("Received MSG: " +
myEnumerator.Current.Body.ToString());
}
 
C

CSharper

Charles,

The MessageEnumerator provides a forward-only cursor to enumerate through
messages in a message queue. In other words, you can view them, but you
can't remove them. In order to remove them, you need to get a reference to
the queue the message is in.
In your case, if myNewPrivateQueue1 is that reference, you can simply call
the Receive method like this:

myNewPrivateQueue1.Receive();

Keep in mind that queues are just that, queues. They operate in a FIFO
(First-in first-out) manner. So when you call receive, you're essentially
getting the message that has been waiting the longest (and has the highest
priority as I understand it).

Hope this helps,

Dan Cox
DISCLAIMER: This *should* work. =)
 
C

Charles Shao

Thank you very much :)
I will go to have a try

CSharper said:
Charles,

The MessageEnumerator provides a forward-only cursor to enumerate through
messages in a message queue. In other words, you can view them, but you
can't remove them. In order to remove them, you need to get a reference to
the queue the message is in.
In your case, if myNewPrivateQueue1 is that reference, you can simply call
the Receive method like this:

myNewPrivateQueue1.Receive();

Keep in mind that queues are just that, queues. They operate in a FIFO
(First-in first-out) manner. So when you call receive, you're essentially
getting the message that has been waiting the longest (and has the highest
priority as I understand it).

Hope this helps,

Dan Cox
DISCLAIMER: This *should* work. =)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top