スレッドを再起動しようとすると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);
}
ように、2つの質問に次のように問題のコードはありますか?