现在它显示温度一次。我希望它像在 openhardwaremonitor 原始程序中一样工作,温度每秒变化/更新一次,或者根据温度是否有任何变化,我不确定它是如何在那里工作的。
我所做的是从构造函数中取出所有 foreach 循环并将其放入计时器滴答事件中。但它不起作用。在 openhardwaremonitor 中,它的显示更改为 51c,而在我的应用程序中,它一直在 44c 上,就像我第一次运行应用程序时一样。
我在 textBox 行上使用了一个断点,有时它到达那里,有时它只是在执行内部循环,但 dosent 将 if 和 dosent 传递到消息框,如果它确实到达消息框,它仍然显示 44c 。
编码:
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();
computer.GPUEnabled = true;
timer1.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
foreach (var hardwareItem in computer.Hardware)
{
if (hardwareItem.HardwareType == HardwareType.GpuNvidia)
{
foreach (var sensor in hardwareItem.Sensors)
{
if (sensor.SensorType == SensorType.Temperature)
{
// MessageBox.Show(String.Format("The current temperature is {0}", sensor.Value));
textBox1.Text = String.Format("The current temperature is {0}", sensor.Value);
}
}
}
}
}
}
}
为什么每次执行循环时它都会更新它不会到达 textBox 行?
如果温度值发生变化或其与 openhardwaremonitor 原始程序中的计时器一起使用,它是否会更新温度?