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" (perhaps because you just created a PerformanceCounter and then used it directly) you need to add 2 lines, as the PerformanceCounter will take some time to work:
System.Threading.Thread.Sleep(1000)
myLabel.Text= cpu.NextValue
To avoid this dream, you might want to declare a PerformanceCounter in your class instead of your Sub / Function and fix problems in the form load event.
Index source
share