C#获取CPU温度

  /// 
        /// 获取cpu温度
        /// 
        /// 
        internal static string GetTemperatureOftheCPU()
        {
            /*
            Mainboard = 0,    主板
            SuperIO = 1,
            CPU = 2,
            RAM = 3,          内存
            GpuNvidia = 4,    显卡
            GpuAti = 5,       A卡
            TBalancer = 6,    声道
            Heatmaster = 7,
            HDD = 8           机械硬盘
            */
            /* 
            Voltage = 0,        电压
            Clock = 1, 时钟
            Temperature = 2,    温度
            Load = 3, 负荷
            Fan = 4,            风扇转速
            Flow = 5, 流
            Control = 6,        控制
            Level = 7,
            Factor = 8, 因子
            Power = 9,          功率
            Data = 10, 数据
            SmallData = 11      小数据
            */
            string m_cpuTemperature = "nuknow";
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer computer = new Computer();
            computer.Open();
            computer.CPUEnabled = true;
            computer.Accept(updateVisitor);
            for (int i = 0; i < computer.Hardware.Length; i++)
            {
                if (computer.Hardware[i].HardwareType == HardwareType.CPU)
                {
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                        {
                            if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                                m_cpuTemperature = computer.Hardware[i].Sensors[j].Value.ToString();
                        }
                    }
                }
            }
            computer.Close();
            return $"{  m_cpuTemperature }℃"; 
        }

 

你可能感兴趣的:(C#)