スレッドを再起動しようとすると、System.Threading.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つの質問-これは物事を行う正しい方法ですか、そしてそれは、エラーの発生を防ぐ方法がありますか?