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") 似乎工作正常。
有什么建议吗?这是为什么?
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);
}
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.
Any suggwstions why is that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除打印机引用有助于消除初始挂起
现在我们收到一条新的错误消息而不是挂起,因此可以跟踪它。来自:
有关打印机驱动程序的解答
我们有两台类似的戴尔笔记本电脑(一台较新),均装有 Windows 8、MVSV 2013 和 IIS Express 8. 一个会挂,一个不会。
Removing printer references helped eliminate a hang on the initial
Now we get a fresh error message instead of hang so can trace it. From:
Answer about printer drivers
We had two similar dell laptops (one newer), both with Windows 8, MVSV 2013, and IIS Express 8. One would hang, one would not.