简体   繁体   English

使用WMI和C#获取MSMQ队列

[英]Get MSMQ Queues using WMI and C#

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

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(Executio 堆栈跟踪:位于System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext()位于System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode),位于c:\\ Users \\ lindj \\ Documents \\ Visuals中的TestGetQueueSize.Program.Main(String [] args) Studio 2012 \\ Projects \\ TestGetQueueSize \\ TestGetQueueSize \\ Program.cs:System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args)位于System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args) System.Threading.ThreadHelper.ThreadStart_Context(对象状态)的System.Threading.ExecutionContext.RunInternal(ExecutionContext执行上下文,ContextCallback回调,对象状态,Boolean状态。在System.Threading.ExecutionContext.Run(Executio)上运行(ExecutionContextexecutionContext,ContextCallback回调,对象状态,布尔值saveSyncCtx) nContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() System.Threading.ThreadHelper.ThreadStart()上的nContext执行上下文,ContextCallback回调,对象状态)

事实证明,尚未安装MSMQ的性能计数器,因此我打开了一个新的问题来处理此问题: 由于缺少性能计数器而导致MSMQ WMI查询失败

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM