我在使用PerformanceCounter时遇到了问题,我想得到cpu的温度,但我只找到了这个:
PerformanceCounter tempCount = new PerformanceCounter(
"Thermal Zone Information",
"Temperature",
@"\_TZ.THRM"); 我还没有找到构造函数值“热区信息”的文档。在哪里可以找到PerformanceCounter的文档?
发布于 2019-03-27 20:04:45
请参考下面的示例,如何获取温度计数器的值:
我已经为性能监视器中的热区信息添加了计数器,如下所示:

这是我的控制台应用程序,它正在获取计数器的值:
using System;
using System.Diagnostics;
using System.Threading;
namespace ConsoleApp
{
public class Program
{
public static void Main(params string[] args)
{
PerformanceCounterCategory performanceCounterCategory = new PerformanceCounterCategory("Thermal Zone Information");
var instances = performanceCounterCategory.GetInstanceNames();
List<PerformanceCounter> temperatureCounters = new List<PerformanceCounter>();
foreach (string instanceName in instances)
{
foreach (PerformanceCounter counter in performanceCounterCategory.GetCounters(instanceName))
{
if (counter.CounterName == "Temperature")
{
temperatureCounters.Add(counter);
}
}
}
while(true)
{
foreach (PerformanceCounter counter in temperatureCounters)
{
Console.WriteLine("{0} {1} {2} {3}",counter.CategoryName,counter.CounterName,counter.InstanceName, counter.NextValue());
}
Console.WriteLine();
Console.WriteLine();
Thread.Sleep(500);
}
}
}
}正如您所看到的,构造函数的值分别是:
PerformanceCounter(
"Thermal Zone Information", // Object
"Temperature", // Counter
@"\_TZ.TZ01") // Instance https://stackoverflow.com/questions/55376313
复制相似问题