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. C# Program Is Eating My CPU Cycles Like Popcorn!

C# Program Is Eating My CPU Cycles Like Popcorn!

Scheduled Pinned Locked Moved C#
csharpquestion
3 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.
  • M Offline
    M Offline
    Michael Fritzius
    wrote on last edited by
    #1

    Hello, I've noticed that when I'm running code, everything becomes devoted to running that program. Most code I write doesn't need to do stuff all the time, just once in awhile it should do a particular operation and then become idle. What's a quick way for me to make sure my programs aren't hogging up resources? Thanks in advance, Michael Fritzius

    P L 2 Replies Last reply
    0
    • M Michael Fritzius

      Hello, I've noticed that when I'm running code, everything becomes devoted to running that program. Most code I write doesn't need to do stuff all the time, just once in awhile it should do a particular operation and then become idle. What's a quick way for me to make sure my programs aren't hogging up resources? Thanks in advance, Michael Fritzius

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      I would use an application like CLR Profiler if I were you. Check this to see where code is inefficient.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      My blog | My articles | MoXAML PowerToys

      1 Reply Last reply
      0
      • M Michael Fritzius

        Hello, I've noticed that when I'm running code, everything becomes devoted to running that program. Most code I write doesn't need to do stuff all the time, just once in awhile it should do a particular operation and then become idle. What's a quick way for me to make sure my programs aren't hogging up resources? Thanks in advance, Michael Fritzius

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, it sounds like you have one or more empty loops, i.e. a loop testing some condition and when (not) met just start the next iteration. Each of those is a good recipe for keeping one core busy. The easy way out is to include a Thread.Sleep(100) in all such loops. The clean approach is to make things entirely event-driven so you don't need polling loops at all. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


        modified on Friday, June 10, 2011 11:25 PM

        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