我在使用PerformanceCounter时遇到了问题,想要获取CPU温度,但我只找到了以下内容:
PerformanceCounter tempCount = new PerformanceCounter(
"Thermal Zone Information",
"Temperature",
@"\_TZ.THRM");
我找不到关于构造函数值 "热区信息" 的文档。PerformanceCounter 的文档在哪里可以找到?
我在使用PerformanceCounter时遇到了问题,想要获取CPU温度,但我只找到了以下内容:
PerformanceCounter tempCount = new PerformanceCounter(
"Thermal Zone Information",
"Temperature",
@"\_TZ.THRM");
我找不到关于构造函数值 "热区信息" 的文档。PerformanceCounter 的文档在哪里可以找到?
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