Hi,
After implementing a game state system based on the one fromt he xna creators website, I decided to expland the laoding screen a little bit by animating something that was being drawn on the screen while things are being loaded int he background.
Without any experience with threading before I decided this was the best way to go, so ill start with posting some code:
Thread renderThread = new Thread(DrawProxy);
renderThread.Start();
foreach (XGameScreen screen in screensToLoad)
if (screen != null)
ScreenManager.AddScreen(screen);
renderThread.Abort();
ScreenManager.RemoveScreen(this);
void DrawProxy()
{
Draw(new GameTime());
}
Probably horrible i know, but bear with me =] The idea was i create a thread which keeps simply calling draw (draw increments the angle of rotation of a sprite and then draws it to the screen) which the main thread loads each game screen, once all the game screens are loaded the thread is removed and the game carrys on.
This all works fine, until i decided to add something silly in jsut to see what happens during a long load, so i simply added a loop into the loading method of one of the screens:
for(int i = 0; i < int.MaxValue; ++i)
{
int j = 1;
}
As you see, completly pointless, but it takes a long[ish] time to execute.
The results were that the sprite rotated until the main program gets to this loop, at which point the sprite stops rotating, and it appears that the thread is no longer working.
Am I missing something I should be doing here? Or is this simply a by product of small pointless loops like the one I have?
Thanks, Scott