国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

如何用C#實時獲取CPU利用率

2024-07-21 02:20:28
字體:
來源:轉載
供稿:網友
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.
[stathread]
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";
}

這是在我計算機上的計算結果:
entering measurement loop.
cpu load = 0 %.
cpu load = 1.941746 %.
cpu load = 4.854369 %.
cpu load = 10 %.
cpu load = 0 %.
cpu load = 2.999997 %.
cpu load = 0.9900987 %.
cpu load = 0 %.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海兴县| 白山市| 通许县| 华蓥市| 明水县| 昌邑市| 静乐县| 苏尼特右旗| 赤水市| 南昌县| 彝良县| 红桥区| 青州市| 肇州县| 本溪市| 沽源县| 大宁县| 雅江县| 东城区| 闵行区| 玛曲县| 洞口县| 井冈山市| 舞阳县| 多伦县| 宁津县| 左云县| 中牟县| 绿春县| 贡山| 开化县| 团风县| 花莲市| 吴江市| 库伦旗| 武功县| 竹山县| 酒泉市| 金坛市| 大关县| 思南县|