How can i add CPU temperature in C#

  • 229 Views
  • Last Post 19 March 2019
Mario Bojarovski posted this 23 February 2019

I want to know how to add CPU temperature in C# windows form 

Order By: Standard | Newest | Votes
java2s posted this 11 March 2019

You can use WMI class to get cpu temperature

First, add a reference to System.Management.dll

To get cpu temperature you can use the query following

double temperature = 0;
string instanceName = "";

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

foreach (ManagementObject obj in searcher.Get())
{
    temperature = Convert.ToDouble(obj["CurrentTemperature"].ToString());
    // Convert your value to celsius degrees
    temperature = (temperature - 2732) / 10.0;
    instanceName = obj["InstanceName"].ToString();
}
Console.WriteLine(temperature);
Console.WriteLine(instanceName);

and don't forget add using to System.Management.

Mario Bojarovski posted this 19 March 2019

Thanks so much, i have i more question : i want to know how can i add CPU temperature in c# windows form. Maybe answer is same but i work alone and nobody can't help me.

Thanks in advance.

Close