<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. 計算機硬件

    用C#語言獲取CPU利用率

    時間:2025-04-25 20:58:35 計算機硬件 我要投稿
    • 相關推薦

    用C#語言獲取CPU利用率

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

      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 %

    【用C#語言獲取CPU利用率】相關文章:

    c#檢測cpu使用率01-02

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

    淺談C#語言的特點05-06

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

    利用C#監控計算機CPU的使用率03-31

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

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

    C語言獲取開機時間07-10

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

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人