首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PerformanceCounter类文档

PerformanceCounter类文档
EN

Stack Overflow用户
提问于 2019-03-27 19:39:56
回答 1查看 312关注 0票数 4

我在使用PerformanceCounter时遇到了问题,我想得到cpu的温度,但我只找到了这个:

代码语言:javascript
复制
PerformanceCounter tempCount = new PerformanceCounter(
    "Thermal Zone Information", 
    "Temperature", 
    @"\_TZ.THRM"); 

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

EN

回答 1

Stack Overflow用户

发布于 2019-03-27 20:04:45

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

我已经为性能监视器中的热区信息添加了计数器,如下所示:

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

代码语言:javascript
复制
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);
            }
        }
    }
}

正如您所看到的,构造函数的值分别是:

代码语言:javascript
复制
PerformanceCounter(
    "Thermal Zone Information",    // Object 
    "Temperature",                 // Counter
    @"\_TZ.TZ01")                  // Instance 
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55376313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档