gpt4 book ai didi

c# - 我怎样才能得到CPU温度?

转载 作者:IT王子 更新时间:2023-10-29 03:48:18 26 4
gpt4 key购买 nike

我需要为正在开发的应用程序收集一些系统信息。使用 C# 可以轻松获得可用内存和 CPU 负载。不幸的是,CPU 温度并不是那么容易。我试过使用 WMI,但我无法使用

Win32_TemperatureProbe

MSAcpi_ThermalZoneTemperature

我该怎么做?我想知道监控程序(如 SiSoftware Sandra)如何获取该信息...

这是类的代码:

public class SystemInformation
{
private System.Diagnostics.PerformanceCounter m_memoryCounter;
private System.Diagnostics.PerformanceCounter m_CPUCounter;

public SystemInformation()
{
m_memoryCounter = new System.Diagnostics.PerformanceCounter();
m_memoryCounter.CategoryName = "Memory";
m_memoryCounter.CounterName = "Available MBytes";

m_CPUCounter = new System.Diagnostics.PerformanceCounter();
m_CPUCounter.CategoryName = "Processor";
m_CPUCounter.CounterName = "% Processor Time";
m_CPUCounter.InstanceName = "_Total";
}

public float GetAvailableMemory()
{
return m_memoryCounter.NextValue();
}

public float GetCPULoad()
{
return m_CPUCounter.NextValue();
}

public float GetCPUTemperature()
{
//...
return 0;
}
}

最佳答案

For others who may come by here, maybe take a look at : http://openhardwaremonitor.org/

点击该链接,起初您可能会想,“嘿,那是一个应用程序,这就是它被删除的原因。问题是如何从 C# 代码执行此操作,而不是找到一个可以告诉我温度的应用程序...”这表明您不愿意花足够的时间来阅读“Open Hardware Monitor”也是什么。

它们还包括一个数据接口(interface)。这是描述:

Data InterfaceThe Open Hardware Monitor publishes all sensor data toWMI (Windows Management Instrumentation). This allows otherapplications to read and use the sensor information as well. Apreliminary documentation of the interface can be found here (click).

当您下载它时,它包含 OpenHardwareMonitor.exe 应用程序,而您并不是要查找该应用程序。它还包含 OpenHardwareMonitorLib.dll,您正在寻找它。

它大部分(如果不是 100%)只是 WinRing0 API 的包装器,如果您愿意,可以选择自己包装。

我自己在 C# 应用程序中尝试过这个,它有效。尽管它仍处于测试阶段,但看起来相当稳定。它也是开源的,因此它可能是一个很好的起点。

关于c# - 我怎样才能得到CPU温度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1195112/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com