De vez en cuando obtengo una System.Threading.ThreadStateException cuando intento reiniciar una cadena. El código en cuestión es la siguiente:Ocurre una excepción ThreadStateException al intentar reiniciar una secuencia
// Make sure the thread is done stopping
while (this.mThread.ThreadState == ThreadState.Running)
{
Thread.Sleep(0);
}
// Respawn a thread if the current one is stopped or doesn't exist
if (this.mThread == null || this.mThread.ThreadState == ThreadState.Stopped)
{
this.mThread = new Thread(new ParameterizedThreadStart(Monitor)); }
// Start the thread
if (check)
{
this.mThread.Start(60000);
}
else
{
this.mThread.Start(0);
}
Así que dos preguntas - es esta la forma correcta de hacer las cosas, y lo es, ¿hay una manera de evitar que el error se produzca?