Created
June 1, 2019 14:32
-
-
Save ttldtor/89c47c4c9b5f3030fe6e3ad8ec731035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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