我用GetSystemInfo()获取到的全是CPU的型号和页面大小等信息,但我要想得到CPU当前的利用率应该怎么做呢???

解决方案 »

  1.   

    using  System;
    using  System.Diagnostics;
    using  System.Threading;
    public  class  CpuLoadInfo  
    {  //  auxiliary  print  methods  
      private  static  void  Say  (  string  txt  )  
      {
        Console.WriteLine(txt);
      }  //  auxiliary  print  methods  
      private  static  void  Say()  
      {
        Say("");
      }  //  The  main  method.  Command  line  arguments  are  ignored.
      [STAThread]
      public  static  void  Main()  
      {
        Say("$Id:  CpuLoadInfo.cs,v  1.2  2002/08/17  17:45:48  rz65  Exp  $");
        Say();    Say("Attempt  to  create  a  PerformanceCounter  instance:");
        Say("Category  name  =  "  +  CategoryName);
        Say("Counter  name    =  "  +  CounterName);
        Say("Instance  name  =  "  +  InstanceName);
        PerformanceCounter  pc
          =  new  PerformanceCounter(CategoryName,CounterName,InstanceName);
        Say("Performance  counter  was  created.");
        Say("Property  CounterType:  "  +  pc.CounterType);
        Say();    Say("Property  CounterHelp:  "  +  pc.CounterHelp);
        Say();
        Say("Entering  measurement  loop.");    while  (true)  
        {
          Thread.Sleep(1000);  //  wait  for  1  second
          float  cpuLoad  =  pc.Nextvalue();
          Say("CPU  load  =  "  +  cpuLoad  +  "  %.");
        }
      }          //  constants  used  to  select  the  performance  counter.
      private  const  string  CategoryName  =  "Processor";
      private  const  string  CounterName    =  "%  Processor  Time";
      private  const  string  InstanceName  =  "_Total";
    }
      

  2.   

    去偶的blog看看吧~~~有几种方法的~~~(带源码)http://blog.csdn.net/lhfzd2004
    http://blog.csdn.net/lhfzd2004/archive/2007/08/02/1722379.aspx
    http://blog.csdn.net/lhfzd2004/archive/2007/08/01/1721687.aspx
      

  3.   

    不仅是顶,顺便给你一个CPU仪表盘的源码:http://www.cnpopsoft.com/article.asp?id=54,呵呵...