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

未找到C#System.Threading.Mutex System.Threading.Mutex.OpenExisting方法,c#,multithreading,cpu-usage,C#,Multithreading,Cpu Usage,我正试图制作一个C#脚本,将CPU温度和使用率统计数据发送到raspberry pi(这是一个LED立方体项目)。我尝试使用Python来实现这一点,但它使用的库psutil不支持Windows上的传感器读数 我正在使用OpenHardwareMonitorLib dll文件尝试获取CPU统计数据。但是,它在“Computer Computer=new Computer();Computer.Open();”行中抛出了一个错误。错误是: “System.MissingMethodExceptio

我正试图制作一个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)'。”

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

  • 安装Powershell 7
  • 将SystemManagement.dll文件添加到项目中(这使我克服了上一个错误)
  • 安装最新的.NET 4.8及其所有附加组件
  • 在应用程序清单中添加了以管理员身份运行的要求
我已经将代码放在Github()上,但这里有一个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();
            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用系统线程;
使用OpenHardwareMonitor.Hardware;
名称空间Get_CPU_Temp5
{
班级计划
{
公共类UpdateVisitor:IVisitor
{
公用无效访问计算机(IComputer计算机)
{
计算机。遍历(本);
}
公共虚拟访问硬件(IHardware硬件)
{
硬件更新();
foreach(硬件中的IHardware subHardware.subHardware)subHardware.Accept(此);
}
公共无效访问传感器(ISensor sensor){}
public void VisitParameter(IPParameter参数){}
}
静态void GetSystemInfo()
{
UpdateVisitor UpdateVisitor=新的UpdateVisitor();
计算机=新计算机();
computer.Open();
computer.CPUEnabled=true;
计算机。接受(updateVisitor);
对于(int i=0;i

我要做的就是获取CPU使用率和CPU温度,并将它们发送到远程IP。我觉得这应该没那么难。

根据您的存储库,您的控制台应用程序似乎是针对
.NET Core
的,但您引用的
.dll
位于
.NET Framework
中。尝试在
中创建您的项目。NETFramework 4.5+

可以。我明天早上试试。我现在就想这么做,但是Windows对我很生气,因为我没有让它打断我的更新。谢谢如果有用的话我会告诉你的,你是最棒的。我真的不知道我在用.NETCore。我只使用过.NET框架,我想这次我也这么做了。我从来没想过要检查一下。