internal void DespawnThread( )
{
#if DEBUG
bool despawned = false;
#endif
// Look for a bored one to despawn.
// Start at the back to despawn new ones first (might have very
// slight performance benefit).
for ( int i = threads.Count - 1; i >= 0; i-- )
{
// Found one!
if ( !threads[i].Running )
{
threads[i].Stop();
threads.RemoveAt(i);
numThreads--;
#if DEBUG
despawned = true;
#endif
break;
}
}
// The DEBUG statements here are to help catch a possible race
// condition. It's not a game breaker, but should be fixed if it
// exists so we'll only fail if we're in debug.
#if DEBUG
if ( !despawned )
throw new Exception("Tried to despawn a Thread but didn't find any bored ones. Is there a race condition?");
#endif
}