How to get CPU frequency in c#

前端 未结 5 661
自闭症患者
自闭症患者 2020-12-03 09:17

How can I get in c# the CPU frequency (example : 2Ghz) ? It\'s simple but I don\'t find it in the environnement variables. Thanks :)

5条回答
  •  半阙折子戏
    2020-12-03 09:43

    Try this code

    using System.Management;
    
    uint currentsp , Maxsp;
    public void CPUSpeed()
    {
       using(ManagementObject Mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'"))
       {
           currentsp = (uint)(Mo["CurrentClockSpeed"]);
           Maxsp = (uint)(Mo["MaxClockSpeed"]);
       }
    }
    

提交回复
热议问题