gpt4 book ai didi

c# - 类 PerformanceCounter 文档

转载 作者:太空宇宙 更新时间:2023-11-03 12:05:19 25 4
gpt4 key购买 nike

我在使用 PerformanceCounter 时遇到问题,我想获取 CPU 温度,但我只找到了这个:

PerformanceCounter tempCount = new PerformanceCounter(
"Thermal Zone Information",
"Temperature",
@"\_TZ.THRM");

我还没有找到有关构造函数值“热区信息”的文档。在哪里可以找到 PerformanceCounter 的文档?

最佳答案

请参阅下面的示例,了解如何获取温度计数器的值:

我在性能监视器中为热区信息添加了计数器,如下所示: enter image description here

这是我的控制台应用程序,它正在获取计数器的值:

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/

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