Reputation: 41
Using the Computer class I successfully retrieved CPU sensor values. However, when it comes to Mainboard, sensor values are not shown every time I run the application. In the most cases the information is not shown, but sometimes it is. What could be the reason that motherboard sensor values are not retrieved every time I run the application?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management;
using OpenHardwareMonitor.Hardware;
using System.Collections;
using System.Data.Common;
using System.Runtime.Remoting.Lifetime;
namespace Test
{
class Program
{
public sealed class OpenHardwareMonitor { }
public class UpdateVisitor : IVisitor
{
public void VisitComputer(IComputer computer)
{
computer.Traverse(this);
}
public void VisitHardware(IHardware hardware)
{
hardware.Update();
foreach (IHardware subHardware in hardware.SubHardware) subHardware.Accept(this);
}
public void VisitSensor(ISensor sensor) { }
public void VisitParameter(IParameter parameter) { }
}
static void GetSystemInfo()
{
UpdateVisitor updateVisitor = new UpdateVisitor();
Computer computer = new Computer();
computer.Open();
computer.CPUEnabled = true;
computer.MainboardEnabled = true;
computer.RAMEnabled = true;
computer.FanControllerEnabled = true;
computer.Accept(updateVisitor);
for (int i = 0; i < computer.Hardware.Length; i++)
{
if (computer.Hardware[i].HardwareType == HardwareType.Mainboard)
{
for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
{
if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
Console.WriteLine(computer.Hardware[i].Sensors[j].Name + ":" + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
}
}
}
computer.Close();
}
static void Main(string[] args)
{
GetSystemInfo();
Console.ReadKey(true);
}
}
}
I tried running it on other PCs but the same thing happens, it sometimes work but usually it doesn't.
Thanks
Upvotes: 1
Views: 260