问题描述
我不知道为什么,但许多计算机挂起如下操作:
I don't know why, but many computers hangs on following operation:
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负载,但程序运行(慢)。像柜等新的PerformanceCounter(处理器,%处理器时间,_Total)
似乎很好地工作。
On some computes program hangs completely on first call of UpdateStats()
, others experiencing 100% CPU load but program works (slowly). Other counters like new PerformanceCounter("Processor", "% Processor Time", "_Total")
seems to work fine.
任何suggwstions这是为什么?
Any suggwstions why is that?
推荐答案
删除打印机引用帮助消除了一个挂在初始
Removing printer references helped eliminate a hang on the initial
new PerformanceCounter("Processor", "% Processor Time", "_Total").
现在我们得到了一个新的错误信息,而不是挂这样可以跟踪它。发件人:
Now we get a fresh error message instead of hang so can trace it. From:
我们有两个相似的戴尔笔记本电脑(一个新的),都与Windows 8中,MVSV 2013和IIS快递8.有人会挂起,人们不会。
We had two similar dell laptops (one newer), both with Windows 8, MVSV 2013, and IIS Express 8. One would hang, one would not.
这篇关于PerformanceCounter.NextValue挂在一些机器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!