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".
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())
{
}
}
Stack Trace: at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext() at TestGetQueueSize.Program.Main(String[] args) in c:UserslindjDocumentsVisual Studio 2012ProjectsTestGetQueueSizeTestGetQueueSizeProgram.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 nContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
事实证明MSMQ的性能计数器没有安装,我已经提出了一个新问题来处理这个问题:由于缺少性能计数器,MSMQ WMI查询失败
链接地址: http://www.djcxy.com/p/95938.html上一篇: 使用Atlassian .NET SDK时的CommunicationException
下一篇: 使用WMI和C#获取MSMQ队列