欧美日韩不卡一区二区三区,www.蜜臀.com,高清国产一区二区三区四区五区,欧美日韩三级视频,欧美性综合,精品国产91久久久久久,99a精品视频在线观看

計(jì)算機(jī)硬件

用C#語言獲取CPU利用率

時(shí)間:2025-04-25 20:58:35 計(jì)算機(jī)硬件 我要投稿
  • 相關(guān)推薦

用C#語言獲取CPU利用率

  CPU是計(jì)算機(jī)使用快慢的關(guān)鍵,因此要時(shí)時(shí)監(jiān)控它,防止它使用率過高,造成卡機(jī)。以下是百分網(wǎng)小編整理的用C#語言獲取CPU利用率,希望對大家有所幫助!更多信息請關(guān)注應(yīng)屆畢業(yè)生考試網(wǎng)!

  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";

  }

  這是在我計(jì)算機(jī)上的計(jì)算結(jié)果:

  Entering measurement loop.

  CPU load = 0 %

【用C#語言獲取CPU利用率】相關(guān)文章:

c#檢測cpu使用率01-02

用C#語言中的修飾符07-22

淺談C#語言的特點(diǎn)05-06

C語言用fstat函數(shù)獲取文件的大小07-24

利用C#監(jiān)控計(jì)算機(jī)CPU的使用率03-31

c語言怎么獲取硬件信息07-23

如何利用PHP語言獲取連接信息05-19

C語言獲取開機(jī)時(shí)間07-10

ruby語言跟c#的一些重要差別06-16