我在使用 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
关于c# - 类 PerformanceCounter 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55376313/