2014-04-07 64 views
0

我在这里找到了我的问题的基本答案:Enumerate all outgoing Queues in MSMQ, C#,但是当我尝试运行发布在答案中的代码时,在抛出异常“无效查询”之前需要几秒到几分钟的时间。使用WMI和C获取MSMQ队列#

ManagementScope scope = new ManagementScope(@"\\"[email protected]"\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(字串[] args)在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() 在System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在System.Threading.ExecutionContext.RunInternal(的ExecutionContext的ExecutionContext,ContextCallback回调,对象的状态,布尔preserveSyncCtx) 在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回调在System.Threading.ThreadHelper.ThreadStart()

+0

你能提供更多的异常细节吗?你有堆栈跟踪吗?当你调用'searcher.get()'时,你什么时候会得到异常? – Gorgsenegger

+0

是的,我调用searcher.Get()时得到异常,异常中没有更多的细节 – JasonLind

回答

0

对象状态,布尔preserveSyncCtx) 在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回调,对象状态) 事实证明为MSMQ的性能计数器没有安装,我已经打开了一个新的问题来处理这个问题:MSMQ WMI Query Failing Due to Missing Performance Counters