I have been asked to build something like the task manager, I need to get a list of processes and how much of the cpu they are using in % value.
These dont need to be running counts i just need what percentage of the cpu was being used when my application started up.
I am getting the cpu percentage using the below code
Public Shared Function GetCpuUsage() As Integer
Dim myCount As Integer
Using cpu = New PerformanceCounter()
With cpu
.CategoryName = "Processor"
.CounterName = "% Processor Time"
.InstanceName = "_Total"
End With
myCount = cpu.NextValue()
System.Threading.Thread.Sleep(1000)
myCount = cpu.NextValue()
System.Threading.Thread.Sleep(1000)
myCount = cpu.NextValue()
End Using
Return myCount
End Function
The question I have is how would i get the % value of each process that is using any cpu usage and ignore anything that is at 0?