I've been trying to figure out what is happening when I run functions from the update loop in XNA that the game freezes for a few seconds until the function is done. When I do performance testing to see how long the function is taking its lower than what is actually being taken to do the function when timed by a stop watch on my phone.
Is there something that is going on with how XNA times its updates and draws that is causing this?
I'm using XNA since MonoGame works with it.
I've got IsFixedTimeStep = false in the constructor of my game that I'm building.
For the update code:
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
this.Exit();
if (Keyboard.GetState().IsKeyDown(Keys.Space))
doOnce = false;
// TODO: Add your update logic here
// trying to determine issue with game freezing when doing the function below.
if (!doOnce)
{
doOnce = true;
startTime = DateTime.Now;
TestFunction();
endTime = DateTime.Now;
timeTakenToScale = new TimeSpan(endTime.Ticks - startTime.Ticks);
}
if (gameTime.TotalGameTime.TotalMilliseconds < nextFrameTime) // don't draw the game unless its past its frame time
{
SuppressDraw();
base.Update(gameTime);
}
else
nextFrameTime = gameTime.TotalGameTime.TotalMilliseconds + maxFrameRate; // set next frame to time
}