4
我不知道为什么,但许多计算机挂起以下操作:PerformanceCounter.NextValue挂在某些机器
void Init()
{
net1 = new List<PerformanceCounter>();
net2 = new List<PerformanceCounter>();
foreach (string instance in new PerformanceCounterCategory("Network Interface").GetInstanceNames())
{
net1.Add(new PerformanceCounter("Network Interface", "Bytes Received/sec", instance));
net2.Add(new PerformanceCounter("Network Interface", "Bytes Sent/sec", instance));
}
}
//Once in 1 second
void UpdateStats()
{
Status.Text = "";
for (int i = 0; i < net1.Count; i++)
Status.Text += string.Format("{0}/{1} Kb/sec; ", net1[i].NextValue()/1024, net2[i].NextValue()/1024);
}
在一些单位计算程序完全挂起的UpdateStats()
第一个电话,其他遇到100%的CPU负载但程序运行缓慢。其他计数器如new PerformanceCounter("Processor", "% Processor Time", "_Total")
似乎工作正常。
任何建议为什么?
基于WTB观察模式的性能计数器,gogo Rx – Aren 2010-05-19 18:00:24
我认为这可能是一个许可问题... – eschneider 2010-05-19 18:43:24
我们在这里有同样的问题。它只是挂起,可能类似于这个:http://sharepoint.nailhead.net/2010/05/application-hangs-caused-by-calling.html 到目前为止,解决方案是有另一个线程来检测是否计数器线程挂起超过预期时间,然后关闭它并实例化另一个线程 – unruledboy 2013-03-19 01:08:25