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. C#
  4. What cpu is my thread executing on?

What cpu is my thread executing on?

Scheduled Pinned Locked Moved C#
performancehelptutorialquestion
4 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.
  • B Offline
    B Offline
    bradsnobar
    wrote on last edited by
    #1

    Hello, I need to throttle a running thread based on the cpu usage that the thread is currently using. My main problem is that my machine has 4 cpu's and I don't know how to figure out which cpu my thread is executing on. (The other cpu's will be used for other queued thread work items, so I can't just look at total cpu usage.) My goal is to poll for cpu usage > 60 % on the current thread and then call thread.sleep until cpu usage returns below that level. I assume that I'll need to use a performance counter to do this. int processorInstance = 'need to figure out what to set this to.' System.Diagnostics.PerformanceCounter c = new System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", processorInstance.ToString()); Thanks, Brad

    P 1 Reply Last reply
    0
    • B bradsnobar

      Hello, I need to throttle a running thread based on the cpu usage that the thread is currently using. My main problem is that my machine has 4 cpu's and I don't know how to figure out which cpu my thread is executing on. (The other cpu's will be used for other queued thread work items, so I can't just look at total cpu usage.) My goal is to poll for cpu usage > 60 % on the current thread and then call thread.sleep until cpu usage returns below that level. I assume that I'll need to use a performance counter to do this. int processorInstance = 'need to figure out what to set this to.' System.Diagnostics.PerformanceCounter c = new System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", processorInstance.ToString()); Thanks, Brad

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      I think there is a way to set the thread affinity (at least through Task Manager), not sure how it can be done programmatically. If it can be done in Task Manager, I don't see why it couldn't be done in a program...

      "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

      B 1 Reply Last reply
      0
      • P Paul Conrad

        I think there is a way to set the thread affinity (at least through Task Manager), not sure how it can be done programmatically. If it can be done in Task Manager, I don't see why it couldn't be done in a program...

        "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

        B Offline
        B Offline
        bradsnobar
        wrote on last edited by
        #3

        I've worked around my problem for now with a well placed thread.sleep for now. Thread affinity looks like the right path to take though. Thanks for the advice.

        P 1 Reply Last reply
        0
        • B bradsnobar

          I've worked around my problem for now with a well placed thread.sleep for now. Thread affinity looks like the right path to take though. Thanks for the advice.

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          Tune us all in if you find anything good :)

          "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

          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