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