How to get CPU temperature in C#
By FoxLearn 2/17/2025 1:56:00 AM 1.14K
This method is more native to Windows but may not always provide CPU temperature information depending on the system and hardware support.
C# get CPU temperature
Although not every motherboard includes a built-in temperature monitor, you can potentially retrieve this information if it's available through Windows Management Instrumentation (WMI). Specifically, you can query the MSAcpi_ThermalZoneTemperature class, which is commonly used for accessing CPU temperature data on some systems.
Most of the information provided by Win32_TemperatureProbe
comes from the System Management BIOS (SMBIOS). However, real-time temperature readings for the CurrentReading
property cannot be directly extracted from SMBIOS tables.
For example, c# cpu temperature
// ManagementObjectSearcher C# ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature"); ManagementObjectCollection objCollection = searcher.Get(); foreach (ManagementObject obj in objCollection) { double temperature = Convert.ToDouble(obj["CurrentTemperature"].ToString()); temperature = (temperature - 2732) / 10.0; // Convert to Celsius Console.WriteLine($"CPU Temperature: {temperature}°C"); }
This example queries the MSAcpi_ThermalZoneTemperature
class in WMI, which is commonly used to retrieve CPU temperature information on some systems. It converts the temperature from Kelvin to Celsius and prints it.
It's a simple way to retrieve the current temperature of your CPU with C# through the WMI class of Windows.
- How to use JsonConverterFactory in C#
- How to serialize non-public properties using System.Text.Json
- The JSON value could not be converted to System.DateTime
- Try/finally with no catch block in C#
- Parsing a DateTime from a string in C#
- Async/Await with a Func delegate in C#
- How to batch read with Threading.ChannelReader in C#
- How to ignore JSON deserialization errors in C#