Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# CPU and GPU Temp

I'm in the process of creating a personal monitoring program for system performance, and I'm having issues figuring out how C# retrieves CPU and GPU Temperature information.

I already have the program retrieve the CPU Load and Frequency information(as well as various other things) through PerformanceCounter, but I haven't been able to find the Instance, Object,and Counter variables for CPU temp.

Also, I need to be able to get the temperature of more than one GPU, as I have two.

What do I do?

like image 362
DanG Avatar asked Oct 31 '22 06:10

DanG


1 Answers

You can use the WMI for that, there is a c# code generator for WMI that helps a lot when creating WMI quires as it is not documented that well.

The WMI code generator can be found here: http://www.microsoft.com/en-us/download/details.aspx?id=8572

a quick try generates something like this:

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

                          foreach (ManagementObject queryObj in searcher.Get())
            {
                Console.WriteLine("-----------------------------------");
                Console.WriteLine("MSAcpi_ThermalZoneTemperature instance");
                Console.WriteLine("-----------------------------------");
                Console.WriteLine("CurrentTemperature: {0}", queryObj["CurrentTemperature"]);
            }
        }
        catch (ManagementException e)
        {
            MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
        }
    }

This may not be exactly what you need just try around with the properties and classes available

like image 193
quadroid Avatar answered Nov 09 '22 05:11

quadroid