This project is read-only.

Closing the game during a loading screen

Jul 24, 2009 at 3:32 AM


I've made a loading screen and I'm loading stuff in an other thread using ThreadPool like you demonstrated in an other discussion.

For now I only load a picture and call Thread.Sleep( 5000 ) to simulate a longer LoadContent().

I noticed that if I close the game during a loading screen, the window closes, but the process stays alive for a little while (until loading is complete).

When I Shutdown() the game I don't really care about a loading thread or anything else, how can I kill the threads that are still running?

Is there a way to access Thread.Abort() for all or a single thread created through ThreadPool?

Jul 24, 2009 at 2:04 PM
Edited Jul 24, 2009 at 2:04 PM

Shutting down the thread pool is actually one of the very last things that happens. It happens after the window has been destroyed. At which stage it waits for all remaining tasks to complete first. If you abort the thread, it actually throws an exception on the thread which you have to catch and deal with. So your best bet is to simply ignore it (the easiest way.. really), or flag your loading process that they should quit early if possible.
It shouldn't crash or hang your game, so overall I don't think a few extra seconds of CPU time would be an issue for most users.