如何在c#中使用开放硬件监视器源代码?我试过什么都行不通

use*_*119 3 c#

我在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)
        {

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

ii 变量为null我不知道如何为它创建一个实例.

构造函数中的其他两个变量不返回0.如果我没有使用ii变量,则其他两个不会抛出错误但不返回任何值.

我正在使用http://code.google.com/p/open-hardware-monitor/downloads/detail?name=openhardwaremonitor-v0.4.0-beta.zip&can=2&q=中的openhardwaremonitor dll

c#dll自带程序.

所以我添加了dll作为参考,但我不知道如何制作代码.

根据我的代码,有人可以为我构建一个代码示例吗?我试着查看openhwardwaremonitor网站和源代码,但不明白如何使用它.

我还可以做些什么 ?

谢谢.

小智 12

我测试了这段代码:

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;

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

该表单具有多行文本控件和计时器.添加引用OpenHardwareMonitorLib.dll.

您还需要在应用程序中请求更高的执行级别,即右键单击项目,添加新的清单文件项并声明

requestedExecutionLevel  level="highestAvailable" uiAccess="false"
Run Code Online (Sandbox Code Playgroud)