# XNA game randomly drops to 40fps

I have a fairly straight forward 2D game written in XNA. I'm finding that it arbitrarily drops from 60fps to 40fps.

I've tested this drop extensively and have concluded it's not related to graphics or the hardware being taxed. What's even stranger is that if I put the window in and out of focus a few times the fps jumps back up to 60.

Sometimes the game load sup at 60fps then I put the window out of focus and back in and it drops to 40fps. This happens anytime, including in the main menu where nothing besides two sprites are being drawn, I've even removed rendering of all sprites just to be sure and it STILL happens, so just a black screen with nothing besides a graphics device clearing the screen.

And before anyone asks, yes, I've manually polled my own functions and have found that everything is being updated and drawn very quickly, it just seems that XNA is taking its sweet time to actually call the update/draw functions.

Does this sound familiar to anyone?

• Not really an answer, but random FPS drops in XNA has happened to me, and my FPS actually increased when I drew something. – DMan Sep 17 '11 at 16:25
• It might be the updating. When you focus out and focus back, XNA will see a big update interval. That might result in more calculations and stuff. – ashes999 Sep 17 '11 at 17:10
• My c++/opengl game does this on windows, but runs at a very stable framerate on linux. I speculate that its something else running 'in the background' on windows but I have no data and I've found nobody else with this problem before... – Will Sep 18 '11 at 18:00
• I found I had some issues with drops in framerate when listening to music (using Winamp). I thought it was random because I wasn't always listening to music. It's possible, as @Will said, that it's something in the background that maybe you take for granted or don't realize is running. – Richard Marskell - Drackir Sep 20 '11 at 3:20

Not sure it's related but I've had a similar problem once, a really weird one where the framerate simply drops and stays low on what seems to be random runs - like every other debug session or after/before switching between fullscreen modes.

It went away when I disabled fixed timestep which didn't feel like a good solution, but it helped and I never really researched why or what the change actually did as that project used the FRB engine.

        IsFixedTimeStep = false;


Tinkering with (changing the default) TargetElapsedTime instead might also help with stuttering and uneven frame rates.

• Why are you setting the TargetElapsedTime when you don't have a Fixed Time Step? – pek Sep 17 '11 at 23:50
• No idea, it was left in there for some reason. As you say, it shouldn't matter when using variable timestep. – Oskar Duveborn Sep 18 '11 at 7:11

That's the expected behaviour. When you put your window in the background, it automatically gets lower priority, thus having a slower update cycle and lowering the framerate.

• Read my question again, it happens even when in focus. – meds Sep 18 '11 at 2:36