Skip to content

Instantly share code, notes, and snippets.

@ttldtor
Created June 1, 2019 14:32
Show Gist options
  • Save ttldtor/89c47c4c9b5f3030fe6e3ad8ec731035 to your computer and use it in GitHub Desktop.
Save ttldtor/89c47c4c9b5f3030fe6e3ad8ec731035 to your computer and use it in GitHub Desktop.
using System;
using OpenHardwareMonitor.Hardware;
namespace hw {
public class UpdateVisitor : IVisitor {
public void VisitComputer(IComputer computer) {
computer.Traverse(this);
}
public void VisitHardware(IHardware hardware) {
hardware.Update();
foreach (var subHardware in hardware.SubHardware) subHardware.Accept(this);
}
public void VisitSensor(ISensor sensor) {
}
public void VisitParameter(IParameter parameter) {
}
}
internal class Program {
static void GetSystemInfo() {
var updateVisitor = new UpdateVisitor();
var computer = new Computer();
computer.Open();
computer.CPUEnabled = true;
computer.Accept(updateVisitor);
foreach (var hardware in computer.Hardware) {
if (hardware.HardwareType != HardwareType.CPU) continue;
foreach (var sensor in hardware.Sensors) {
if (sensor.SensorType == SensorType.Temperature)
Console.WriteLine($"{sensor.Name}:{sensor.Value.ToString()}");
}
}
computer.Close();
}
public static void Main(string[] args) {
GetSystemInfo();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment