LibreHardwareMonitor不显示GPU传感器。

huangapple go评论78阅读模式
英文:

LibreHardwareMonitor doesn't show GPU sensors

问题

以下是您提供的代码的翻译部分:

尽管 Libre Hardware Monitor 显示了我的 GPU 传感器数据,但下面的代码仅适用于我感兴趣的 GPU 硬件。它适用于我也不理解的所有其他硬件。

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Runtime.Remoting.Lifetime;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using LibreHardwareMonitor;
using LibreHardwareMonitor.Hardware;
using LibreHardwareMonitor.Software;
using LibreHardwareMonitor.Interop;

namespace mynamespace
{
    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) { }
    }

    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 Monitorr()
        {
            Computer computer = new Computer
            {
                IsCpuEnabled = false,
                IsGpuEnabled = true,
                IsMemoryEnabled = false,
                IsMotherboardEnabled = false,
                IsControllerEnabled = false,
                IsNetworkEnabled = false,
                IsStorageEnabled = false,
                IsPsuEnabled = false
            };

            computer.Open();
            computer.Accept(new UpdateVisitor());

            foreach (IHardware hardware in computer.Hardware)
            {
                Console.WriteLine("Hardware: {0}", hardware.Name + ":" + hardware.HardwareType);

                foreach (IHardware subhardware in hardware.SubHardware)
                {
                    Console.WriteLine("\tSubhardware: {0}", subhardware.Name);

                    foreach (ISensor sensor in subhardware.Sensors)
                    {
                        Console.WriteLine("\t\tSensor: {0}, value: {1}", sensor.Name, sensor.Value);
                    }
                }

                foreach (ISensor sensor in hardware.Sensors)
                {
                    Console.WriteLine("\tSensor: {0}, value: {1}", sensor.Name, sensor.Value);
                }
            }

            computer.Close();
        }
        static void Main(string[] args)
        {
            while (true)
            {
                Monitorr();// Thread.Sleep(20000000); }//adjust refresh intervals (ms)
            }
        }
    }
}

我找不到为什么它不提供 GPU 数据的解释。请帮助。这是我的第一个 Stack Overflow 问题。谢谢。

英文:

Even though the Libre Hardware Monitor shows my gpu sensor data, this code below will not work only for the gpu hardware which I was interested in. It works for ALL other hardware which I also don't understand.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Runtime.Remoting.Lifetime;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using LibreHardwareMonitor;
using LibreHardwareMonitor.Hardware;
using LibreHardwareMonitor.Software;
using LibreHardwareMonitor.Interop;
namespace mynamespace
{
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) { }
}
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 Monitorr()
{
Computer computer = new Computer
{
IsCpuEnabled = false,
IsGpuEnabled = true,
IsMemoryEnabled = false,
IsMotherboardEnabled = false,
IsControllerEnabled = false,
IsNetworkEnabled = false,
IsStorageEnabled = false,
IsPsuEnabled = false
};
computer.Open();
computer.Accept(new UpdateVisitor());
foreach (IHardware hardware in computer.Hardware)
{
Console.WriteLine("Hardware: {0}", hardware.Name + ":" + hardware.HardwareType);
foreach (IHardware subhardware in hardware.SubHardware)
{
Console.WriteLine("\tSubhardware: {0}", subhardware.Name);
foreach (ISensor sensor in subhardware.Sensors)
{
Console.WriteLine("\t\tSensor: {0}, value: {1}", sensor.Name, sensor.Value);
}
}
foreach (ISensor sensor in hardware.Sensors)
{
Console.WriteLine("\tSensor: {0}, value: {1}", sensor.Name, sensor.Value);
}
}
computer.Close();
}
static void Main(string[] args)
{
while (true)
{
Monitorr();// Thread.Sleep(20000000); }//adjust refresh intervals (ms)
}
}
}
}

I couldn't find an explanation why it doesn't give gpu data. Please help. This is my first stack overflow question. Thank you.

答案1

得分: 2

尝试将您的构建平台更改为 x64
在搜索解决方案约 5 小时后,对我有效...
我也发现,直到您以管理员特权运行应用程序,才能获取主板上的所有传感器。

英文:

Try to change your build platform to x64
It's worked for me after searching for solution for about 5 hours...
I've found too that not all sensors from Mainboard will be achieved until you run your app with Admin Privileges.

huangapple
  • 本文由 发表于 2023年2月16日 05:26:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465583.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定