我在 Form1 中有这段代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenHardwareMonitor.Hardware.HDD;
using OpenHardwareMonitor;
namespace OpenHardwareMonitor
{
public partial class Form1 : Form
{
OpenHardwareMonitor.Hardware.SensorValue sv;
OpenHardwareMonitor.Hardware.ISensor ii;
public Form1()
{
InitializeComponent();
string y = ii.Name;
sv = new Hardware.SensorValue();
DateTime dt = sv.Time;
float t = sv.Value;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
ii
变量为空我不知道如何为其创建一个实例。
构造函数中的另外两个变量不返回 0。如果我不使用ii
变量其他两个不会抛出错误,但不返回任何值。
我正在使用 openhardwaremonitor dll
C# dll 是随程序本身一起提供的。
所以我添加了 dll 作为参考,但我不知道如何编写代码。
有人可以根据我的代码为我构建一个代码示例吗?
我尝试查看 openhwardwaremonitor 站点和源代码,但不明白如何使用它。
我还可以做些什么 ?
Thanks.
我测试过这段代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenHardwareMonitor;
using OpenHardwareMonitor.Hardware;
namespace CPUTemperatureMonitor
{
public partial class Form1 : Form
{
Computer thisComputer;
public Form1()
{
InitializeComponent();
thisComputer = new Computer() { CPUEnabled = true };
thisComputer.Open();
}
private void timer1_Tick(object sender, EventArgs e)
{
String temp = "";
foreach (var hardwareItem in thisComputer.Hardware)
{
if (hardwareItem.HardwareType == HardwareType.CPU)
{
hardwareItem.Update();
foreach (IHardware subHardware in hardwareItem.SubHardware)
subHardware.Update();
foreach (var sensor in hardwareItem.Sensors)
{
if (sensor.SensorType == SensorType.Temperature)
{
temp += String.Format("{0} Temperature = {1}\r\n", sensor.Name, sensor.Value.HasValue ? sensor.Value.Value.ToString() : "no value");
}
}
}
}
textBox1.Text = temp;
}
}
}
该表单有一个多行文本控件和一个计时器。添加参考OpenHardwareMonitorLib.dll
.
您还需要在应用程序中请求更高的执行级别,即右键单击项目,添加新的清单文件项并声明
requestedExecutionLevel level="highestAvailable" uiAccess="false"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)