C# Application - Reduce CPU Usage
- run the timer event less frequently
- do the work on a worker thread (so the UI is at least responsive)
- do less work in the timer (or do it more efficiently)
- get more CPU
I'm guessing you really mean the third bullet, but we can't answer that without knowing what the code is doing; but (random suggestions without any context):
- look at any collection access to see if there is a place for a dictionary, hash-set, or similar
- check if you are doing vast amounts of IO (in particular to a DB) which could be reduced
- check if you are going lots of thread-switches via
Invoke
(or the UI's equivalent)
You're in wondering and guessing mode. Forget CPU percent. What pros do is find out why the program's spending time and if it's necessary.
What you could do is just run that code flat out in a long loop, and sample it. I use this method. Stack samples will land preferentially in the heavy branches of the call tree. Chances are you can lop off some of those heavy branches and get a nice speedup.