我如何使用C#开放的硬件监控器的源代码?我想任何事情不工作 [英] How can I use open hardware monitor source code in c# ? I tried anything doesn't work
问题描述
我在Form1的代码:
I have this code in 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
变量为空我不知道如何为它的一个实例。
ii
variable is null I don't know how to make an instance for it.
在构造函数返回0无其他两个变量。如果我不使用 II
变量的另外两个不抛出一个错误,但不返回任何值。
The other two variables in the constructor return 0 nothing. If I'm not using the ii
variable the other two don't throw an error but don't return any values.
C#的DLL与程序它自身未来
The c# dll is coming with the program it self.
所以,我添加为基准的DLL,但我不知道如何使代码。
So I added as reference the dll but I don't know how to make the code.
可能有人只是按照我这里的代码代码示例为我造?
我试图在openhwardwaremonitor网站和源代码那里看看,不明白如何使用它。
Could someone build for me just an example of the code according to my code here ? I tried to look in the openhwardwaremonitor site and source code there and didn't understand how to use it.
我还能做什么?
感谢
推荐答案
我已经测试此代码:
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
。
您还需要在应用程序中请求更高的执行水平,即右键单击该项目,添加一个新的清单文件项,申报
You also need to request a higher execution level in the application, i.e. right click on the project, add a new manifest file item and declare
requestedExecutionLevel level="highestAvailable" uiAccess="false"
这篇关于我如何使用C#开放的硬件监控器的源代码?我想任何事情不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!