使用C#检索CPU温度 [英] Retrieving CPU Temperature using C#

查看:102
本文介绍了使用C#检索CPU温度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检索计算机的CPU温度。我在下面发布了我的代码。有人可以告诉我我的问题在哪里吗?



I am trying to retrieve a computer's CPU temp. I have posted my code below. Can someone please tell me where my problem is?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace SServer.Common.Diagnostics.SystemInfo
{
    public class Temperature
    {
        public double CurrentValue { get; set; }
        public string InstanceName { get; set; }
        public static List<string> Temperatures
        {
            get
            {
                List<string> result = new List<string>();

                ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\CIMV2", "SELECT * FROM Win32_TemperatureProbe");

                foreach (ManagementObject obj in searcher.Get())
                {
                    if (obj != null)
                    {
                        Double temp = Convert.ToDouble(obj["CurrentTemperature"].ToString());

                        temp = (temp - 2732) / 10.0;

                        result.Add(new Temperature
                        {
                            CurrentValue = temp,
                            InstanceName = obj["CurrentTemperature"].ToString()
                        }.ToString());
                    }
                }
                return result;
            }
        }
    }
}

推荐答案

CurrentTemperature不存在 - 它当前正在阅读。



但是我有更多的坏消息:这可能也不会有用。

参见MSDN: Win32_TemperatureProbe类 [ ^ ]



Win32_TemperatureProbe WMI类提供的大部分信息来自SMBIOS。无法从SMBIOS表中提取CurrentReading属性的实时读数。因此,当前的实现WMI没有填充CurrentReading属性。当前读取属性的存在保留供将来使用。
CurrentTemperature does not exist - it is CurrentReading.

But I have more bad news for you: that probably won't work either.
See MSDN: Win32_TemperatureProbe class[^]

"Most of the information that the Win32_TemperatureProbe WMI class provides comes from SMBIOS. Real-time readings for the CurrentReading property cannot be extracted from SMBIOS tables. For this reason, current implementations of WMI do not populate the CurrentReading property. The CurrentReading property's presence is reserved for future use."


这篇关于使用C#检索CPU温度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆