我有一个简单的监控应用程序,它正在从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秒。
我能做些什么(如果有的话)来加快计数器的创建?
30秒听起来像是超时,这表明这可能是某种网络问题。
尝试使用不指定主机名的构造函数创建perfmon计数器,看看这是否有帮助:
PerformanceCounter c = new PerformanceCounter("PhysicalDisk", "Avg. Disk Read Queue Length", "_Total");