在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 System.Management;
using OpenHardwareMonitor.Hardware;
namespace NvidiaTemp
{
public partial class Form1 : Form
{
Computer computer = new Computer();
public Form1()
{
InitializeComponent();
computer.Open();
var temps = new List<decimal>();
foreach (var hardware in computer.Hardware)
{
if (hardware.HardwareType != HardwareType.CPU)
continue;
hardware.Update();
foreach (var sensor in hardware.Sensors)
{
if (sensor.SensorType != SensorType.Temperature)
{
if (sensor.Value != null)
temps.Add((decimal)sensor.Value);
}
}
}
foreach (decimal temp in temps)
{
Console.WriteLine(temp);
MessageBox.Show(temp.ToString());
}
Console.ReadLine();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
它永远不会进入 foreach 跳过它。尝试了这么多示例示例无法弄清楚如何使其工作。而且我确定我的视频卡支持它,因为如果我运行 origiran openhardwaremonitor 程序 ikts 会如何处理所有参数,如温度和速度......
刚刚从程序官网下载了openhwardwaremonitor.dll文件:
http://openhardwaremonitor.org/downloads/ 该dll位于它自己的程序目录中。