Ok so I'm trying to get the CPU usage using a PerformanceCounter
in Visual Studio 2010 but the problem I'm having is when I add the PerformanceCounter
and try to add a CategoryName
the list is empty along with CounterName
and InstanceName
.
I also tried adding the counter using the following code but it still doesn't work:
Imports System.Diagnostics
Dim myCounter As System.Diagnostics.PerformanceCounter = New System.Diagnostics.PerformanceCounter()
myCounter.CategoryName = "Processor"
myCounter.CounterName = "% Processor Time"
myCounter.InstanceName = "_Total"
ProgressBar1.Value = myCounter.NextValue.ToString
cpuTxt.Text = "CPU Usage: " & ProgressBar1.Value.ToString & "%"
Any idea why this is happening? I've been searching for some time now and still can't get it to work. Any help is greatly appreciated.