現在,它顯示一次溫度。 我希望它能像openhardwaremonitor原創程序那樣工作,即溫度每秒更新/更新或根據溫度是否有任何變化進行更新,我不確定它在那裏如何工作。使用OpenHardwareMonitor庫的輸出每n秒更新一個文本框
我所做的是從構造函數中取出所有的foreach循環,並將其放入計時器tick事件中。但它的工作。在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);
}
}
}
}
}
}
}
爲什麼它dosent更新dosent到文本框中行其每個做循環時間?
如果溫度值發生變化或者在openhardwaremonitor原始程序中使用定時器工作,是否更新溫度?
*提示*:使用linq代替每個嵌套。 另外...對不起,但我真的不明白你想問什麼。 – Yoeri 2012-07-31 22:34:28