Question

I found the basic answer to my question here: Enumerate all outgoing Queues in MSMQ, C#, however when I try to run the code posted in the answer it takes several seconds to several minutes before throwing an exception "Invalid Query".

ManagementScope scope = new ManagementScope(@"\\"+Environment.MachineName+@"\root\cimv2");
SelectQuery query = new SelectQuery("SELECT * FROM Win32_PerfRawData_MSMQ_MSMQQueue");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
{
   foreach (var queue in searcher.Get())
   {

   }
}

Stack Trace: at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext() at TestGetQueueSize.Program.Main(String[] args) in c:\Users\lindj\Documents\Visual Studio 2012\Projects\TestGetQueueSize\TestGetQueueSize\Program.cs:line 18 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

Was it helpful?

Solution

As it turns out the performance counters for MSMQ are not installed, I've opened a new question to deal with this problem: MSMQ WMI Query Failing Due to Missing Performance Counters

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top