使用WMI和C#获取MSMQ队列

我在这里找到了我的问题的基本答案:枚举MSMQ,C#中的所有传出队列,但是当我尝试运行发布在答案中的代码时,需要几秒到几分钟才会抛出异常“无效查询”。

ManagementScope scope = new ManagementScope(@""+Environment.MachineName+@"rootcimv2");
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()at TestGetQueueSize.Program.Main(String [] args)在c: Users lindj Documents Visual Studio 2012 Projects TestGetQueueSize TestGetQueueSize Program.cs:System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args) System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔preserveSyncCtx)System.Threading.ThreadHelper.ThreadStart_Context(对象状态)上的.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()在System.Threading.ExecutionContext。在System.Threading.ExecutionContext.Run执行(ExecutionContext executionContext,ContextCallback回调,Object状态,布尔preserveSyncCtx)(执行 nContext executionContext,ContextCallback回调,对象状态)在System.Threading.ThreadHelper.ThreadStart()


事实证明MSMQ的性能计数器没有安装,我已经提出了一个新问题来处理这个问题:由于缺少性能计数器,MSMQ WMI查询失败

链接地址: http://www.djcxy.com/p/95937.html

上一篇: Get MSMQ Queues using WMI and C#

下一篇: Set value of private field