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