哪位高手知道在C#中如何获得进程的CPU利用率,小弟很着急

解决方案 »

  1.   

    用WMI试下,该命名空间为:
    using System.Management;
    很多系统相关的东西都在里面
      

  2.   

    Win32_ProcessorThe Win32_Processor WMI class represents a device that can interpret a sequence of machine instructions on a computer running a Windows® operating system. On a multiprocessor machine, one instance of the Win32_Processor class exists for each processor.The following syntax is simplified from Managed Object Format (MOF) code and includes all inherited properties.
    class  Win32_Processor : CIM_Processor
    {
      uint16 AddressWidth;
      uint16 Architecture;
      uint16 Availability;
      string Caption;
      uint32 ConfigManagerErrorCode;
      boolean ConfigManagerUserConfig;
      uint16 CpuStatus;
      string CreationClassName;
      uint32 CurrentClockSpeed;
      uint16 CurrentVoltage;
      uint16 DataWidth;
      string Description;
      string DeviceID;
      boolean ErrorCleared;
      string ErrorDescription;
      uint32 ExtClock;
      uint16 Family;
      datetime InstallDate;
      uint32 L2CacheSize;
      uint32 L2CacheSpeed;
      uint32 LastErrorCode;
      uint16 Level;
      uint16 LoadPercentage;
      string Manufacturer;
      uint32 MaxClockSpeed;
      string Name;
      string OtherFamilyDescription;
      string PNPDeviceID;
      uint16 PowerManagementCapabilities[];
      boolean PowerManagementSupported;
      string ProcessorId;
      uint16 ProcessorType;
      uint16 Revision;
      string Role;
      string SocketDesignation;
      string Status;
      uint16 StatusInfo;
      string Stepping;
      string SystemCreationClassName;
      string SystemName;
      string UniqueId;
      uint16 UpgradeMethod;
      string Version;
      uint32 VoltageCaps;
    };
    关注一下
    LoadPercentage 属性:
    Data type: uint16
    Access type: Read-only
    Qualifiers: Units(Percent) Load capacity of each processor, averaged to the last second. Processor loading refers to the total computing burden for each processor at one time. This property is inherited from CIM_Processor.我也没有做过类似的功能,还请楼主试下
      

  3.   

    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cssample/html/vcsamperfmonsamplecsharp.htmCPU USAGE开源:
    http://www.mentalis.org/soft/class.qpx?id=12