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. Trying to find the usage of the CPU

Trying to find the usage of the CPU

Scheduled Pinned Locked Moved Visual Basic
databasedebuggingquestionannouncement
4 Posts 3 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'm trying to get the percentage of the CPU Usage. So far I have the following code: Dim query1 As New ManagementObjectSearcher("SELECT * From Win32_Processor") Dim moa1 As ManagementObject Dim tempa1 As Long For Each moa1 In query1.Get() tempa1 = Long.Parse(moa1("LoadPercentage").ToString()) Label3.Text = tempa1 Next When I debug with a break point and leave the mouse pointer over the label3.text I get the value of the percentange, but when i run the program without a break point the program seams for ever thinking without giving me the value. I have a timer that runs every second to update the query. What am I doing wrong? Thank you. Still trying to find the way

    D 1 Reply Last reply
    0
    • C Chaos Machine

      Hello everybody. I'm trying to get the percentage of the CPU Usage. So far I have the following code: Dim query1 As New ManagementObjectSearcher("SELECT * From Win32_Processor") Dim moa1 As ManagementObject Dim tempa1 As Long For Each moa1 In query1.Get() tempa1 = Long.Parse(moa1("LoadPercentage").ToString()) Label3.Text = tempa1 Next When I debug with a break point and leave the mouse pointer over the label3.text I get the value of the percentange, but when i run the program without a break point the program seams for ever thinking without giving me the value. I have a timer that runs every second to update the query. What am I doing wrong? Thank you. Still trying to find the way

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

      You shouldn't be using WMI for this. Instead, you should be using the Performance Counters. Check out this[^] example on MSDN. It's doing exactly what you described. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You shouldn't be using WMI for this. Instead, you should be using the Performance Counters. Check out this[^] example on MSDN. It's doing exactly what you described. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        S Offline
        S Offline
        Scott Serl
        wrote on last edited by
        #3

        Actually WMI IS used for accessing performance counters: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/monitoring_performance_data.asp[^]

        D 1 Reply Last reply
        0
        • S Scott Serl

          Actually WMI IS used for accessing performance counters: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/monitoring_performance_data.asp[^]

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

          I didn't say you couldn't get the perf data using WMI. I said, you SHOULDN'T use WMI for it. If you want Performance Counter data, use the PerformanceCounter classes. It's what they're there for and you don't have to wrap a bunch of WMI junk to get something that's already been wrapped for you. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          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