如何计算队列和打印的消息数量 [英] How do I count number of messages queues and print

查看:66
本文介绍了如何计算队列和打印的消息数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手。我以前从未尝试过这个。我有这个查询



I new to this. I have never tried this before. I have this query

string queryString = String.Format(@"SELECT * FROM Win32_PerfFormattedData_msmq_MSMQQueue");
            var query = new ObjectQuery(queryString);
            var searcher = new ManagementObjectSearcher(scope, query);
            IEnumerable<int> messageCountEnumerable =
                from ManagementObject queue in searcher.Get()
                select (int)(UInt64)queue.GetPropertyValue("MessagesInQueue");
            //IEnumerable<string> messageCountEnumerable =
            //  from ManagementObject queue in searcher.Get()
            //  select (string)queue.GetPropertyValue("Name");
            var x = messageCountEnumerable.First();

            return x;



如何在此处传递队列?



我尝试了什么:



这是我的通话方式:




how do I pass my queues here?

What I have tried:

this is my calling method :

var mQuery = from x in q select new { qName = x.QueueName, msgCount = GetMessageCount(x, machineName, "", "") };
               //select new { qName = x.QueueName, msgCount = GetMessageCount(string.Format("\\private$\\{0}", x.QueueName), machineName, "", "") };

               Console.WriteLine("Queue Name and number of messages in Queues \n-----------------------------------------------------------\n");
               foreach (var item in mQuery)
               {
                   Console.WriteLine(string.Format("{0}\t[{1}]", item.qName, item.msgCount));
                   Console.WriteLine();
               }

推荐答案

\\ {0},x.QueueName),machineName, ,)};

Console.WriteLine( 队列名称和队列中的消息数\ n ----------------------------------------- ------------------ \ n);
foreach var item in mQuery)
{
Console.WriteLine( string .Format( {0} \t [{1}],item.qName,item.msgCount));
Console.WriteLine();
}
\\{0}", x.QueueName), machineName, "", "") }; Console.WriteLine("Queue Name and number of messages in Queues \n-----------------------------------------------------------\n"); foreach (var item in mQuery) { Console.WriteLine(string.Format("{0}\t[{1}]", item.qName, item.msgCount)); Console.WriteLine(); }


只需添加查询路径并正确格式化:



just added query path and formatted it correctly :

int pos1 = queuePath.IndexOf('\\');
          int pos2 = queuePath.LastIndexOf('\\');
          string qPath1 = queuePath.Insert((pos1 + 1), "\\");
          string qPath = qPath1.Insert((pos2 + 1), "\\");

          string queryString = String.Format("SELECT * FROM Win32_PerfFormattedData_msmq_MSMQQueue WHERE NAME ='{0}'", qPath);


这篇关于如何计算队列和打印的消息数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆