How do I get the cpu usage percentage to display in the label on a form?
Import Namespace System.Diagnostics
' ...
Dim cpu as New PerformanceCounter()
With cpu
.CategoryName = "Processor"
.CounterName = "% Processor Time"
.InstanceName = "_Total"
End With
' ...
myLabel.Text = cpu.NextValue()
codekaizen said:
Import Namespace System.Diagnostics
Dim cpu as New PerformanceCounter()
With cpu
.CategoryName = "Processor"
.CounterName = "% Processor Time"
.InstanceName = "_Total"
End With
myLabel.Text = cpu.NextValue()
In case you end up with "0" (probably because you just created the PerformanceCounter and then directly used it) you need to add 2 lines as the PerformanceCounter need some time to work:
System.Threading.Thread.Sleep(1000)
myLabel.Text= cpu.NextValue
To Avoid that sleep you might want to declare the PerformanceCounter in your Class instead of your Sub/Function and set the probs in the forms loading event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With