PerformanceCounter PC = new PerformanceCounter();//性能计数器
PC.CategoryName = "Process";//性能计数器-进程
PC.CounterName = "% Processor Time";//
PC.InstanceName = othervlcprocess.ProcessName;
然后用PC.NextValue()取出来的值一直为零,其实othervlcprocess.ProcessName该进程一直占有3%左右的cpu,
这是为什么,请高手指点!

解决方案 »

  1.   

    借鉴下 http://www.cnblogs.com/chiropter/articles/1971956.html 
    部分内容:
    很多人在使用PerfomanceCounter的时候直接new PerfomanceCounter实例,然后就去调用NextValue()方法。这样往往得到的值是0.00,今天我也犯了这么错误,找个了半天,终于发现,performance counter在计算值得时候,需要两个样本,如果我们获取到PerformanceCounter后直接调用NextValue()方法,则只会获取到第一个样本的值,该值往往会是0
      

  2.   

    灰常感谢你的回答,我已经得到这个值了,但现在有一个问题,如果我的cpu占用率为0,但通过NextValue()为什么还是有值的?cpu为3%的那个进程的值反而比cpu为0的那个值小,这是为什么NextValue()不是得到CPU的占用率吗?我的目地是把我自己的进程中,cpu为0的进程杀掉