我在这里找到了我的问题的基本答案:Enumerate all outgoing Queues in MSMQ, C#,但是当我尝试运行答案中发布的代码时,需要几秒到几分钟才会抛出异常"无效查询&#34 ;
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())
{
}
}
堆栈跟踪: 在System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) 在System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext() 在TestGetQueueSize.Program.Main(String [] args)中的c:\ Users \ lindj \ Documents \ Visual Studio 2012 \ Projects \ TestGetQueueSize \ TestGetQueueSize \ Program.cs:第18行 在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args) 在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 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) 在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态) 在System.Threading.ThreadHelper.ThreadStart()
答案 0 :(得分:0)
事实证明没有安装MSMQ的性能计数器,我已经开了一个新问题来处理这个问题:MSMQ WMI Query Failing Due to Missing Performance Counters