Click here to Skip to main content
15,882,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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()
        myCount = cpu.NextValue()
        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?

Share this answer
Sergey Alexandrovich Kryukov 15-Nov-12 22:03pm    
That is something else, also useful stuff, a 5.
Espen Harlinn 16-Nov-12 3:25am    
Thank you, Sergey :-D
For such purposes, you can use WMI, or System.Management,[^].

This is a nice and short introductory article:[^].

This is what you will need to query CPU usage:[^].


There is a number of code samples with some cookbook recipes for WMI query which you can easily find if you Google; for example:[^].

Just one relevant code sample:[^].

And this is the CodeProject article on the topic:[^].

I hope it's enough for you to solve your problem.

Good luck,
Share this answer
Espen Harlinn 15-Nov-12 19:43pm    
Well answered :-D
DinoRondelly 15-Nov-12 19:45pm    
Thank you very much this will help with a few problems
Sergey Alexandrovich Kryukov 15-Nov-12 22:02pm    
Thank you, Espen.
DinoRondelly 15-Nov-12 21:55pm    
this was exactly what i needed !!!!!
Sergey Alexandrovich Kryukov 15-Nov-12 22:01pm    
Great. -- You are very welcome.
Good luck, call again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900