개발/C#

[C#] CPU 이용률 알아보기.

-=HaeJuK=- 2010. 4. 23. 17:50

CPU 이용률 알아보기

현재 시스템의 CPU 사용률을 알아 봅시다.

 

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/******************************************************************************
* _    _                 _       _  __  _____               _           _     
*| |  | |               | |     | |/ / |  __ \             | |         | |    
*| |__| | __ _  ___     | |_   _| ' /  | |  | | _____   __ | |     __ _| |__  
*|  __  |/ _` |/ _ \_   | | | | |  <   | |  | |/ _ \ \ / / | |    / _` | '_ \ 
*| |  | | (_| |  __/ |__| | |_| | . \  | |__| |  __/\ V /  | |___| (_| | |_) |
*|_|  |_|\__,_|\___|\____/ \__,_|_|\_\ |_____/ \___| \_(_) |______\__,_|_.__/ 
*
* Copyright (c) HaeJuK Dev Lab All Rights Reserved.
*
*******************************************************************************/                                                                             
 
using System.Diagnostics ;
protected PerformanceCounter cpuCounter;
 
public MyMain(LoginData _Data)
{
    cpuCounter = new PerformanceCounter();
    cpuCounter.CategoryName = "Processor";                 
    cpuCounter.CounterName = "% Processor Time";
    cpuCounter.InstanceName = "_Total";
}
 
private void MyMain_Load(object sender, EventArgs e)
{
    Timer T = new Timer();
    T.Interval = 1000;
    T.Tick += new EventHandler(UseingCpuPer);
    T.Start();
}
 
public void UseingCpuPer(Object sender , EventArgs e)
{
    progressBar3.Value= (int)cpuCounter.NextValue();
    label54.Text = progressBar3.Value.ToString();
}
cs
반응형