Is there a better way to count the messages in an Message Queue (MSMQ)?

Posted by Damovisa on Stack Overflow See other posts from Stack Overflow or by Damovisa
Published on 2010-04-12T00:00:50Z Indexed on 2010/04/12 0:03 UTC
Read the original article Hit count: 212

Filed under:
|
|

I'm currently doing it like this:

MessageQueue queue = new MessageQueue(".\Private$\myqueue");
MessageEnumerator messageEnumerator = queue.GetMessageEnumerator2();
int i = 0;
while (messageEnumerator.MoveNext())
{
    i++;
}
return i;

But for obvious reasons, it just feels wrong - I shouldn't have to iterate through every message just to get a count, should I?

Is there a better way?

© Stack Overflow or respective owner

Related posts about msmq

Related posts about c#