0

I'm trying to get status data of my processor on the local machine. I found several tutorials online, but no one of them covers the error I'm getting.

This is my code:

        UpdateVisitor visitor = new UpdateVisitor();

        Computer computer = new Computer();
        computer.Open();
        computer.CPUEnabled = true;

        computer.Accept(visitor);

It throws an Exception when calling computer.Open() and this is the exception message:

enter image description here

What am i doing wrong? If i can provide some more detail, please let me know. I'm referencing the library in a .NET Standard 2.0 project.

mororo
  • 1,074
  • 2
  • 11
  • 28

2 Answers2

0

Solved the problem by referencing the library in a .NET Framework 4.7.1 project, instead that in a .NET Standard 2.0 project. I post this answer just to warn other people trying to achieve this that this library is not fully compatible with .NET Standard code.

mororo
  • 1,074
  • 2
  • 11
  • 28
-2

I stole this WMI Answer from this question: C# CPU and GPU Temp. Just install System.Management and start VS in Admin mode, and you can access the sensors.

using System;
using System.Diagnostics;
using System.Management;
class Program
{
   static void Main(string[] args)
   {
       Double CPUtprt = 0;
       System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(@"root\WMI", "Select * From MSAcpi_ThermalZoneTemperature");
       foreach (System.Management.ManagementObject mo in mos.Get())
       {
           CPUtprt = Convert.ToDouble(Convert.ToDouble(mo.GetPropertyValue("CurrentTemperature").ToString()) - 2732) / 10;
          Console.WriteLine("CPU temp : " + CPUtprt.ToString() + " °C");
       }
   }
}
  • My question is about using a specific library. Sorry, but your answer is only suggesting to use another one. – mororo Aug 29 '19 at 13:40