In form1 i did:
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)
{
}
}
}
Its never get in to the foreach jump over it.
Tried so many samples examples cant figure out how ot make it work. And im sure my video card support it since if im running the origiran openhardwaremonitor program ikts howing all parameters like temepratures and speeds…
Just downloaded the openhwardwaremonitor.dll file from the official program website:
http://openhardwaremonitor.org/downloads/
the dll is in the directory of the program it self.
I broke out ILSpy and took a look at the example exe that ships with the download, as the documentation is quite rudimentary – which is often the case 🙂
I noticed that when the
Computerobject is initialized, the boolean properties likeGPUEnabledare set to true.So…
When I run that code from a Windows Forms app on my machine, I get the current temperature (38C, which means I’m obviously not running it hard enough!)
If I do not set GPUEnabled, I get exactly the same result as you – no items in the
IHardwarecollection.UPDATE:
To answer the other question you posed in the comments, an example like the following should work for you:
Here we have a
Windows.Forms.Timerand theComputerclass as class level variables which we initialize in the constructor. Every 5 seconds, thetickevent will fire, enumerating the hardware, and displaying a message box with the current temp in. This could easily be a label, and you could even store theSensorin a class level variable to avoid enumerating theIHardwarecollection each time.Hope this helps!