尝试重新启动线程时,我经常会遇到System.Threading.ThreadStateException。有问题的代码如下:尝试重新启动线程时发生ThreadStateException
// 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);
}
所以两个问题 - 这是做事的正确方法,它是,有没有办法来防止错误的发生?