Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Calculating the CPU usage of ONE process with VB.NET 2003

Calculating the CPU usage of ONE process with VB.NET 2003

Scheduled Pinned Locked Moved Visual Basic
helpquestioncsharptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chaos Machine
    wrote on last edited by
    #1

    Hello everybody, I have a big issue that I can't seem to be able to solve. I need to find a SINGLE CPU process (one program that I know the name of), and display it into a label. For example My_program ---> 20% I use (on a timer) Private m_PerformanceCounter As New System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total") ListBox1.Items.Add(CInt(m_PerformanceCounter.NextValue()) & "%") but I think I get ALL processes added up. I just want ONE of them for example (in pseudocode) if process.name = "My_program" then label1.text=process.CPUUsageTimeOfTHatProcess How can I do it with VB.NET? Any help will be much appreciated. Thank you in advance.

    Still trying to find the way

    D 1 Reply Last reply
    0
    • C Chaos Machine

      Hello everybody, I have a big issue that I can't seem to be able to solve. I need to find a SINGLE CPU process (one program that I know the name of), and display it into a label. For example My_program ---> 20% I use (on a timer) Private m_PerformanceCounter As New System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total") ListBox1.Items.Add(CInt(m_PerformanceCounter.NextValue()) & "%") but I think I get ALL processes added up. I just want ONE of them for example (in pseudocode) if process.name = "My_program" then label1.text=process.CPUUsageTimeOfTHatProcess How can I do it with VB.NET? Any help will be much appreciated. Thank you in advance.

      Still trying to find the way

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Of course it's returning the total CPU usage. Look at the line of code your using:

      Chaos Machine wrote:

      Private m_PerformanceCounter As New System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total")

      On top of this, you don't even need the Performance counters to do this. You can get a processes CPU time using the process' Process object. Checkout the Process class[^] and it's TotalProcessorTime and UserProcessorTime properties.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups