4

A fresh XNA game project application consumes quite some CPU percentage while its window is active. On my desktop PC it's about 30% of one core of a 2-core processor. When the window loses focus, the game goes into idle mode and consumes about 1% of CPU.

In an image viewer application I recently made using XNA, redrawing frames when no image manipulation is going on doesn't make much sense, so I'm using the SuppressDraw() method which, as the name suggests, suppresses spending resources for drawing the next frame, showing the last drawn frame instead. But still, there's a problem where the application keeps wasting CPU for a very simple input update.

How do I reduce the CPU usage for an XNA application when it doesn't require much of it?

user1306322
  • 8,561
  • 18
  • 61
  • 122
  • profile your application to see where it is spending its processing time. Then change the execution flow to avoid unnecessary processing. – axon May 23 '13 at 03:05
  • @axon as I said, the input update is very simple. The application doesn't consume a lot when its window is not in focus, but when it is, it's way too high for doing nothing. – user1306322 May 23 '13 at 04:01
  • You could simply add Sleep(100) to the main loop. No point rendering 100s of frames per second if there's no benefit. Alternatively, have a target frame rate and adjust your sleep time to hit that target. – axon May 23 '13 at 04:50
  • @axon I really don't think this is an option for a PC XNA application. – user1306322 May 23 '13 at 05:24
  • It is. You really should try it. "If you actually need to wait a specific amount of time for something, then sleep is appropriate." From: http://stackoverflow.com/questions/1096794/is-sleep-evil Of course, if you are using a framework that has this already implemented, then use it – axon May 23 '13 at 07:55

1 Answers1

4

quote from this question

According to this discussion on XBox Live Indie Games forum , apparently on some processors (and OS-s) XNA takes up 100% CPU time on one core when the default value of Game.IsFixedTimeStep is used.

A common solution (one that worked for me as well) is to put the following in your Game constructor: IsFixedTimeStep = false;

more details here

Community
  • 1
  • 1
Dmi7ry
  • 1,777
  • 1
  • 13
  • 25