关于System.Diagnostics.PerformanceCounter的使用的疑问

intelserver 2004-01-07 07:31:06
我在对CPU使用时间上碰到问题:

PC.NextValue();
有Class B,
Class B
{
PC = new PerformanceCounter("Processor",
"% Processor Time","_Total");
public int nextValue;
void abc()
{
nextValue = PC.NextValue();
}
}
我在Class A中,引用了Class B,Class B中声明了一个PC对象
Class A
{
while ( true )
{
b = new ClassB();
int i = b.nextvalue; <-----------想每次获取PC的新值,但未如愿
}
}

本意是不断地获取ClassB中 PC计数器的新值,事实上i每次的值都是0,没有获取
连续值,请问该如何解决这个问题?
...全文
295 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
intelserver 2004-01-07
  • 打赏
  • 举报
回复
为什么每次PC.NextValue()的值都是0呢?
有没有CurrentValue呢?
可以获取CPU当前的使用率吗?
IceboundRock 2004-01-07
  • 打赏
  • 举报
回复
Class A
{
B b = new B();
int i = 0;
void Refeash_i()
{
while ( true )
{
b.acb();
i = b.nextvalue; <-----------想每次获取PC的新值,但未如愿
}
}
}

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧