I am attempting this:
using System.Diagnostics;
// ...
var queueCounter = new PerformanceCounter(
"MSMQ Queue",
"Messages in Queue",
@"machinename\private$\testqueue2");
Console.WriteLine( "Queue contains {0} messages",
queueCounter.NextValue().ToString());
Which came from this post: Is there a way to check how many messages are in a MSMQ Queue?
There is mention of this same error, but no resolution when using PerformanceCounter.
I also found mention here: Performance Counter - System.InvalidOperationException: Category does not exist
However, this thread started on this exact topic, but went another direction before answering the initial question on what to do about the error. Basically I don't need to know records per second, I only need to know when a queue starts getting backed up.
What causes this error? I have tried pointing to private and public queue's as well as pointing to queues that had messages in them.
Edit: I have added the counter in perfmon to ensure I have the server path and queue name correct.