1. Dans ta Form (je suppose que tu travailles avec Windows Forms ?), déclare une variable cpuCounter :
Private cpuCounter As System.Diagnostics.PerformanceCounter
2. Dans l'initialisation de ta form (dans le constructeur ou dans le Form_Load), initialise cette variable :
1 2 3 4
| cpuCounter = New System.Diagnostics.PerformanceCounter()
cpuCounter.CategoryName = "Processor"
cpuCounter.CounterName = "% Processor Time"
cpuCounter.InstanceName = "_Total" |
3. A chaque fois que tu as besoin de connaître l'utilisation du processeur, appelle NextValue, et affiche la valeur obtenue où tu veux (par exemple un label) :
LabelCPU.Text = cpuCounter.NextValue().ToString()
Partager