CPU temperature monitoring

后端 未结 3 1695
小鲜肉
小鲜肉 2020-12-01 06:49

For a programming project I would like to access the temperature readings from my CPU and GPUs. I will be using C#. From various forums I get the impression that there is sp

3条回答
  •  再見小時候
    2020-12-01 07:13

    For at least the CPU side of things, you could use WMI.

    The namespace\object is root\WMI, MSAcpi_ThermalZoneTemperature

    Sample Code:

    ManagementObjectSearcher searcher = 
        new ManagementObjectSearcher("root\\WMI",
                                     "SELECT * FROM MSAcpi_ThermalZoneTemperature");
    
    ManagementObjectCollection collection = 
        searcher.Get();
    
    foreach(ManagementBaseObject tempObject in collection)
    {
        Console.WriteLine(tempObject["CurrentTemperature"].ToString());
    }
    

    That will give you the temperature in a raw format. You have to convert from there:

    kelvin = raw / 10;
    
    celsius = (raw / 10) - 273.15;
    
    fahrenheit = ((raw / 10) - 273.15) * 9 / 5 + 32;
    

提交回复
热议问题