I am trying to use the OpenHardwareMonitorLib DLL to get the temperature of my CPU \ cores, however this doesn't return the temperature for me.
I have looked around and seen that this is a problem almost everywhere but I cannot get this to work.
I would be very appreciative if someone can tell me where I am going wrong with this.
This is my code:
using System;
using System.Linq;
using System.Management;
using OpenHardwareMonitor.Collections;
using OpenHardwareMonitor.Hardware;
using OxyPlot;
using OxyPlot.Series;
namespace cs_TempReader
{
class Program
{
private DateTime now;
protected readonly ListSet<ISensor> active = new ListSet<ISensor>();
public event SensorEventHandler SensorAdded;
public event SensorEventHandler SensorRemoved;
protected virtual void ActivateSensor(ISensor sensor)
{
if (active.Add(sensor))
if (SensorAdded != null)
SensorAdded(sensor);
}
private static void Main(string[] args)
{
var myComputer = new Computer();
myComputer.CPUEnabled = true;
myComputer.ToCode();
myComputer.Open();
foreach (var hardwareItem in myComputer.Hardware)
{
hardwareItem.Update();
hardwareItem.GetReport();
Console.WriteLine(hardwareItem.GetReport());
var series = new LineSeries();
foreach (var sensor in hardwareItem.Sensors)
{
if (sensor.SensorType == SensorType.Temperature)
{
Console.WriteLine("{0} {1} {2} = {3}", sensor.Name, sensor.Hardware, sensor.SensorType, sensor.Value);
}
}
}
}
}
}
My ultimate goal is to be able to tie this into a bigger application.
You need to request a higher execution level in the application so this code can work properly.
To do this you have to:
After that you have to change this line on the manifest:
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
To this:
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />