我正在尝试使用 OpenHardwareMonitorLib DLL 来获取我的 CPU \ 内核的温度,但是这不会为我返回温度。
我环顾四周,发现这几乎无处不在,但我无法让它发挥作用。
如果有人能告诉我哪里出了问题,我将不胜感激。
这是我的代码:
using System;
using System.Linq;
using System.Management;
using OpenHardwareMonitor.Collections;
using OpenHardwareMonitor.Hardware;
using OxyPlot;
using OxyPlot.Series;
namespace cs_TempReader
{
class Program
{
private DateTime now;
protected readonly ListSet<ISensor> active = new ListSet<ISensor>();
public event SensorEventHandler SensorAdded;
public event SensorEventHandler SensorRemoved;
protected virtual void ActivateSensor(ISensor sensor)
{
if (active.Add(sensor))
if (SensorAdded != null)
SensorAdded(sensor);
}
private static void Main(string[] args)
{
var myComputer = new Computer();
myComputer.CPUEnabled = true;
myComputer.ToCode();
myComputer.Open();
foreach (var hardwareItem in myComputer.Hardware)
{
hardwareItem.Update();
hardwareItem.GetReport();
Console.WriteLine(hardwareItem.GetReport());
var series = new LineSeries();
foreach (var sensor in hardwareItem.Sensors)
{
if (sensor.SensorType == SensorType.Temperature)
{
Console.WriteLine("{0} {1} {2} = {3}", sensor.Name, sensor.Hardware, sensor.SensorType, sensor.Value);
}
}
}
}
}
}
我的最终目标是能够将其与更大的应用程序联系起来。