I have a call to get the count of a MSMQ that is failing.
After some research, I found this question: Reading MSMQ message count with ruby
The answer there indicates that if a Queue is empty and Closed that you cannot get "Performance Metrics" (including message count).
So my question now is, how can I programatically "Open" (ie "Un-Close") a MSMQ using .NET and C#?
Update: Incase it is relevant, here is my code to get the message count:
private static int GetMessageCount(string queueName, string machine)
{
MSMQManagement queue = new MSMQManagement();
string formatName = @"DIRECT=OS:" + machine + @"\PRIVATE$\" + queueName;
queue.Init(machine, null, formatName);
return queue.MessageCount;
}
The error occurs on queue.Init
. The error message is: "The queue is not open or may not exist."
This code works just fine on another queue that is setup just the same (but is not empty).