I was wondering if there is a way to programmatically check how many messages are in a private or public MSMQ using C#? I have code that checks if a queue is empty or not using the peek method wrapped in a try/catch, but I've never seen anything about showing the number of messages in the queue. This would be very helpful for monitoring if a queue is getting backed up.
Navigate to 'Computer Management (Local) > Services and Applications > Message Queueing > Private Queues' and verify that the two private queues used by my application are visible.
Answers. Hi, Based on my research, MSMQ supports messages under 4 MB in size only and each message needs 75 bytes of kernel memory for indexing. The maximum number of messages that MSMQ can hold is based on the size of free space on the volume you have created on the disk in your server.
You can set the queue manager attribute value in the range 32768 bytes through 100 MB; you can set the queue attribute value in the range 0 through 100 MB.
Since it exists in Windows 10 and Windows Server 2019, MSMQ will continue to live on until at least 2029—and much longer assuming it isn't removed from future versions of Windows. The System. Messaging namespace lives on in . NET Framework 4.8 (which will be its last release ever, being completely supplanted by .
You can read the Performance Counter value for the queue directly from .NET:
using System.Diagnostics; // ... var queueCounter = new PerformanceCounter( "MSMQ Queue", "Messages in Queue", @"machinename\private$\testqueue2"); Console.WriteLine( "Queue contains {0} messages", queueCounter.NextValue().ToString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With