c# - 类 PerformanceCounter 文档

标签 c#

我在使用 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/

相关文章:

c# - Convert.ToDouble 出于某种未知原因抛出 System.FormatException

c# - DropDownListForModel 无法添加 HTML 属性

c# - Mono.Addin 实现不检索插件

c# - 如何通过 LINQ 在二维数组中进行搜索?[version2]

c# - Nsubstitute:如何在泛型类中创建一个假的

c# - XML 序列化以将请求发送到 SOAP 服务 C#

c# - 使 C# 程序集属性详细显示

c# - Listener 类更改我表单上的文本标签

C# 线程和 this.Invalidate()

c# - 为什么 UI 不会在 RaisePropertyChanged 上更新?