Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSAcpi_ThermalZoneTemperature class not showing actual temperature

Tags:

c#

i want to fetch CPU Performance data in real time including temperature. i used the following code to get CPU Temperature:

try
        {
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher("root\\WMI",
                "SELECT * FROM MSAcpi_ThermalZoneTemperature");

            foreach (ManagementObject queryObj in searcher.Get())
            {
                double temp = Convert.ToDouble(queryObj["CurrentTemperature"].ToString());
                double temp_critical = Convert.ToDouble(queryObj["CriticalTripPoint"].ToString());
                double temp_cel = (temp/10 - 273.15);
                double temp_critical_cel = temp_critical / 10 - 273.15;
                lblCurrentTemp.Text = temp_cel.ToString();
                lblCriticalTemp.Text = temp_critical_cel.ToString();
            }
        }
        catch (ManagementException e)
        {
            MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
        }

but this code shows the temperature that is not the correct temperature. It ususally shows 49.5-50.5 degrees centigrade. But I used "OpenHardwareMonitor" that report CPU temperature over 71 degree centigrade and changing fractions along with time fractions. is there anything I am missing in the code?

I used the above code in timer_click event for every 500ms interval to refresh the temperature reading but it's always showing the same temperature from the beginning of execution. That implies if you run this application and if it shows 49 degree then after 1 hour session, it'll constantly show 49 degree. Where is the problem?

like image 383
jchoudhury Avatar asked Feb 01 '12 18:02

jchoudhury


1 Answers

In https://web.archive.org/web/20150911113852/http://www.scriptinternals.com/new/us/support/Internal/WMI_MSAcpi_ThermalZoneTemperature.htm I've found that CurrentTemperature returns temperature at some thermal zone which is somewhere on motherboard. That means it returns not CPU temperature. It would be the same as temperature in the kitchen is 30C but stove is 200C or so... This way cannot show exact temperature of CPU. To get the exact temperature of CPU (and every core) you need to write kernel drivers, what is much more complicated.

All-in-all your code does that it should do, for taking temperature you need to use some other way.

like image 118
ST3 Avatar answered Nov 15 '22 05:11

ST3