成人午夜激情影院,小视频免费在线观看,国产精品夜夜嗨,欧美日韩精品一区二区在线播放

當前位置:首頁>>開發編程>>VS.NET>>新聞內容
如何用C#實時獲取CPU利用率
作者:孟憲會 發布時間:2004-8-24 9:55:10 文章來源:孟憲會之精彩世界
<!--StartFragment-->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 %.

最新更新
·C#中使用Split分隔字符串的技
·VS2008開發中Windows Mobile
·PC機和移動設備上絕對路徑的
·C#程序加殼的方法(使用Sixx
·當前上下文中不存在名稱Conf
·請插入磁盤:Visual Studio 2
·用VS.NET讀取Flash格式文件信
·在ASP.NET中使用AJAX的簡單方
·VS.NET 2005中常用的一些代碼
·安裝VS.NET 2005 SP1補丁全攻
相關信息
·C#中使用Split分隔字符串的技巧
·PC機和移動設備上絕對路徑的獲取(C#)
·C#程序加殼的方法(使用Sixxpack)
·當前上下文中不存在名稱ConfigurationManager的解決方法
·C#的支付寶Payto接口代碼
·C#實現窗口最小化到系統托盤
·解密QQ的MsgEx.db消息文件格式
·QQ的TEA填充算法C#實現
·C#用Guid獲取不規則的唯一值(標識)
·基于Windows Mobile 5.0的掌上天氣預報設計
畫心
愚愛
偏愛
火苗
白狐
畫沙
犯錯
歌曲
傳奇
稻香
小酒窩
獅子座
小情歌
全是愛
棉花糖
海豚音
我相信
甩蔥歌
這叫愛
shero
走天涯
琉璃月
Nobody
我愛他
套馬桿
愛是你我
最后一次
少女時代
灰色頭像
斷橋殘雪
美了美了
狼的誘惑
我很快樂
星月神話
心痛2009
愛丫愛丫
半城煙沙
旗開得勝
郎的誘惑
愛情買賣
2010等你來
我叫小沈陽
i miss you
姑娘我愛你
我們都一樣
其實很寂寞
我愛雨夜花
變心的玫瑰
犀利哥之歌
你是我的眼
你是我的OK繃
貝多芬的悲傷
哥只是個傳說
丟了幸福的豬
找個人來愛我
要嫁就嫁灰太狼
如果這就是愛情
我們沒有在一起
寂寞在唱什么歌
斯琴高麗的傷心
別在我離開之前離開
不是因為寂寞才想你
愛上你等于愛上了錯
在心里從此永遠有個你
一個人的寂寞兩個人的錯
主站蜘蛛池模板: 讷河市| 沿河| 桐庐县| 杭锦后旗| 普陀区| 灵宝市| 会宁县| 正安县| 和静县| 古蔺县| 安图县| 天等县| 桓台县| 绥宁县| 建平县| 安达市| 太仆寺旗| 白玉县| 新平| 张北县| 景东| 河南省| 萨嘎县| 涞源县| 宜良县| 潢川县| 自贡市| 宝坻区| 龙南县| 公安县| 临清市| 肇州县| 伊川县| 新晃| 青田县| 神农架林区| 望城县| 珲春市| 济源市| 商都县| 东乌珠穆沁旗|