创建一个新的System.Diagnostics.PerformanceCounter很慢 [英] Creating a new System.Diagnostics.PerformanceCounter is very slow

查看:256
本文介绍了创建一个新的System.Diagnostics.PerformanceCounter很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的监视应用程序,该应用程序从PerfMon计数器获取一些值.即使在本地计算机上进行测试,创建新的PerformanceCounter对象也要花费30秒以上的时间.

I have a simple monitoring application that is getting some values from PerfMon counters. Even when testing on the local machine, it is taking over 30 seconds to create a new PerformanceCounter object.

using System;
using System.Diagnostics;

namespace test_slow_perfmon
{
    class Program
    {
        static void Main(string[] args)
        {
            Stopwatch w = new Stopwatch();

            w.Start();
            PerformanceCounter c = new PerformanceCounter("PhysicalDisk", "Avg. Disk Read Queue Length", "_Total", "localhost");
            w.Stop();
            Console.WriteLine(string.Format("Creating a counter took {0}ms", w.Elapsed.TotalMilliseconds));
        }
    }
}

从中输出表示要创建每个计数器的时间超过32秒.

Output from that indicates over 32s to create each counter.

我该怎么做(如果有的话)来加快计数器的创建速度?

What can I do (if anything) to speed up the creation of the counters?

推荐答案

30秒对我来说听起来像是超时,可疑的是,这表明我可能是某种网络问题.

30 seconds sounds to me suspiciously like a timeout, indicating to me that this could be some sort of network issue.

尝试使用未指定主机名的构造函数创建您的性能计数器看看是否有帮助:

Try creating your perfmon counter using the constructor that doesn't specify a hostname and see if that helps:

PerformanceCounter c = new PerformanceCounter("PhysicalDisk", "Avg. Disk Read Queue Length", "_Total");

这篇关于创建一个新的System.Diagnostics.PerformanceCounter很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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