以下是关于OpenHardwareMonitor的示例代码C#的答案:
OpenHardwareMonitor是一个开源的硬件监控软件,可以实时监控CPU、GPU、内存等硬件的温度、频率、电压等参数。它支持Windows操作系统,并且提供了C#的API接口,可以方便地集成到其他应用程序中。
以下是一个简单的示例代码,演示如何使用OpenHardwareMonitor的C# API获取CPU和GPU的温度和电压:
using System;
using System.Threading;
using OpenHardwareMonitor.Hardware;
namespace OpenHardwareMonitorExample
{
class Program
{
static void Main(string[] args)
{
// 创建OpenHardwareMonitor的实例
Computer computer = new Computer();
computer.Open();
// 获取CPU和GPU的温度和电压
foreach (var hardwareItem in computer.Hardware)
{
hardwareItem.Update();
foreach (var sensor in hardwareItem.Sensors)
{
if (sensor.SensorType == SensorType.Temperature || sensor.SensorType == SensorType.Voltage)
{
Console.WriteLine($"{hardwareItem.Name} - {sensor.Name}: {sensor.Value} {sensor.Unit}");
}
}
}
// 关闭OpenHardwareMonitor的实例
computer.Close();
Console.ReadKey();
}
}
}
需要注意的是,OpenHardwareMonitor的C# API需要安装OpenHardwareMonitor的库才能使用。可以在NuGet包管理器中搜索“OpenHardwareMonitorLib”并安装。
推荐的腾讯云相关产品:腾讯云云服务器、腾讯云数据库、腾讯云CDN、腾讯云对象存储、腾讯云负载均衡、腾讯云API网关、腾讯云云审计、腾讯云安全中心、腾讯云监控等。
产品介绍链接地址:腾讯云官网
领取专属 10元无门槛券
手把手带您无忧上云