Search All Articles Submit your Website or Blog to A New Internet Library
Monday, August 17, 2009
To get the count of messages in a MSMQ Queue in C#.NET
There is no direct property provided with MessageQueue class.
We can use GetMessageEnumerator2 to get the enumerator to enumerate and get the count of number of messages present in the queue.
The below code is used for getting the messages count from a transactional queues
public static int GetMessageCount(MessageQueue messageQueue)
{
int count = 0;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
MessageEnumerator enumerator = messageQueue.GetMessageEnumerator2();
while (enumerator.MoveNext(new TimeSpan(0, 0, 0)))
{
count++;
}
}
return count;
}
The below code is used for getting the messages count from a non transactional queues
public static int GetMessageCount(MessageQueue messageQueue)
{
int count = 0;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
MessageEnumerator enumerator = messageQueue.GetMessageEnumerator2();
while (enumerator.MoveNext(new TimeSpan(0, 0, 0)))
{
count++;
}
}
return count;
}
Subscribe to:
Post Comments (Atom)
Also Read other Top Articles
- JSON Serialization in VS 2008
- Implementing Forms Authentication in Silverlight Application.
- Making GridView Rows or Individual Cells Clickable and Selectable.
- Enabling browser back button for GridView Paging and Sorting in Ajax 1.1 and 3.5 (using Visual Studio 2005/ Visual studio 2008)
- How to pass values from User Control to Page or calling Page methods from User Control.
- What is WCF?
- New features in C# 4.0
- C# to VB.NET and VB.NET to C# online free converter tools.


1 comments:
Thanks for gr8 information.
I found good resources of c#. Check this out
http://CSharpTalk.com
Post a Comment
Post your comments/questions/feedback for this Article.