【发布时间】:2012-07-23 12:13:35
【问题描述】:
我有一个简单的监控应用程序,它从 PerfMon 计数器中获取一些值。即使在本地机器上进行测试,创建一个新的PerformanceCounter 对象也需要 30 多秒。
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 秒。
我可以做些什么(如果有的话)来加快计数器的创建速度?
【问题讨论】:
-
32 秒???尝试“。”时是否更快?作为“localhost”的机器名称?
标签: c# performancecounter