c#如何获得cpu温度
大家好,RT。
有没有哪个函数能获取cpu温度?
cpu使用率呢?
谢谢!
[解决办法]
using System;using System.Diagnostics;class Program{ static void Main(string[] args) { PerformanceCounter[] counters = new PerformanceCounter[ System.Environment.ProcessorCount ]; for(int i=0; i<counters.Length; i++) { counters[i] = new PerformanceCounter("Processor", "% Processor Time", i.ToString()); } while(true) { for(int i=0; i<counters.Length; i++) { float f = counters[i].NextValue(); Console.WriteLine("CPU-{0}: {1:f}%", i, f); } Console.WriteLine(); System.Threading.Thread.Sleep(1000); } }}
[解决办法]
Double CPUtprt = 0;System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(@"root\WMI", "Select * From MSAcpi_ThermalZoneTemperature");foreach (System.Management.ManagementObject mo in mos.Get()){ CPUtprt = Convert.ToDouble(Convert.ToDouble(mo.GetPropertyValue("CurrentTemperature").ToString()) - 2732) / 10;textBox1.Text = ("CPU 溫度 : " + CPUtprt.ToString() + " °C");}
[解决办法]