C# System.Threading.Mutex System.Threading.Mutex.OpenExisting 方法未找到

C# System.Threading.Mutex System.Threading.Mutex.OpenExisting Method Not found

我正在尝试制作一个 C# 脚本来将 CPU 温度和使用统计信息发送到 raspberry pi(这是一个 LED 立方体项目)。我尝试使用 Python 来执行此操作,但它使用的库 psutil 不支持 Windows 上的传感器读数。

我正在使用 OpenHardwareMonitorLib dll 文件来尝试获取 CPU 统计信息。但是,它抛出一个错误赢得了“Computer computer = new Computer(); computer.Open();”行。错误是:

"System.MissingMethodException: '找不到方法:'System.Threading.Mutex System.Threading.Mutex.OpenExisting(System.String, System.Security.AccessControl.MutexRights)'.'""

我已经尝试了我能想到的一切以及我在 google 上找到的一切。我记不太清了,但这些是其中的一些:

我已将代码放在 Github (https://github.com/verdammte/led_cube) 上,但这里是有问题的 C# 代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using OpenHardwareMonitor.Hardware;

namespace Get_CPU_Temp5
{
    class Program
    {
        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.Accept(updateVisitor);
            for (int i = 0; i < computer.Hardware.Length; i++)
            {
                if (computer.Hardware[i].HardwareType == HardwareType.CPU)
                {
                    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)
        {
            while (true)
            {
                GetSystemInfo();
            }
        }
    }
}

我只想获取 CPU 使用情况和 CPU 温度并将它们发送到远程 IP。我觉得这不应该这么难。

根据您的存储库,您的控制台应用程序似乎以 .NET Core 为目标,但您引用的 .dll.NET Framework 中。尝试在 .NET Framework 4.5+.

中创建项目