Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
722 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...