-
查看CPU信息
现在我们来讲一下如何利用C#开发一个时时获取CPU使用率的程序,首先我们来看一下
public class CpuLoadInfo
这个CpuLoadInfo是用于加载CPU信息的一个类,接下来在类中可以看到首先声明两个方法
第一个是有参数的Say方法,第二个是没有参数的Say方法,分别是在控制台输出信息和调用
原来的Say方法。
接下为在主方法中,调用第一个Say方法输出各种信息
using System;
using System.Diagnostics;
using System.Threading;
public class CpuLoadInfo
{
// auxiliary print methods
private static void Say(string txt)
{
Console.WriteLine(txt);
}
// auxiliary print methods
private static void Say()
{
Say("");
}
// The main method. Command line arguments are ignored.
public static void Main()
{
Say("$Id: CpuLoadInfo.cs,v 1.2 2002/08/17 17:45:48 rz65 Exp $");
Say();
Say("Attempt to create a PerformanceCounter instance:");
Say("Category name = " + CategoryName);
Say("Counter name = " + CounterName);
Say("Instance name = " + InstanceName);
PerformanceCounter pc = new PerformanceCounter (CategoryName,CounterName,InstanceName);
Say("Performance counter was created.");
Say("Property CounterType: " + pc.CounterType);
Say();
Say("Property CounterHelp: " + pc.CounterHelp);
Say();
Say("Entering measurement loop.");
while(true)
{
Thread.Sleep(1000); // wait for 1 second
float cpuLoad = pc.NextValue();
Say("CPU load = " + cpuLoad + " %.");
}
}
// constants used to select the performance counter.
private const string CategoryName = "Processor";
private const string CounterName = "% Processor Time";
private const string InstanceName = "_Total";
}
最新更新
王炸!!IDEA 2021.1 推出语音、视频功能,
并发编程之ThreadLocal
为什么 DNS 协议使用 UDP?只使用了 UDP 吗
死磕Spring之AOP篇 - Spring AOP注解驱动与XM
学习笔记:Java中的数据结构——数组
Mybatis的日志工厂
rabbitmq五种模式详解(含实现代码)
rabbitmq五种模式详解(含实现代码)
ArryaList源码浅析
jasypt在springboot项目中遇到异常:Error cr
JAVA oa 办公系统模块 设计方案
MongoDB vs MySQL,哪个效率更高?
NoSql非关系型数据库之MongoDB应用(三):M
10分钟系列:NetCore3.1+EFCore三步快速完成数
NoSql非关系型数据库之MongoDB应用(一):安
NoSql非关系型数据库之MongoDB应用(二):安
【干货】SqlServer 总结几种存储过程分页的
SQLServer存储过程自制数据字典
MYSQL事务篇(高级篇)
mysql常用语句 3
Taro 3.4 beta 发布: 支持 Preact 为应用开辟
前端---梳理 http 知识体系 2
Java入门到架构师全新课程之JavaScript数据
构造函数与实例化之间的关系和原型的引
Vue库的使用
IIS安装和ASP.NET Web应用程序开发期间部署
ASP.NET MVC IOC依赖注入之Autofac系列开篇
ASP.NET中WebService的创建和部署以及通过反
ASP.NET Core Web 应用程序开发期间部署到I
ASP.NET Core Web 应用程序系列(一)- 使用