有两个线程:主线程和附加线程。附加线程无限循环工作,应在主线程结束或应用程序结束后停止。你能告诉我告诉 AdditionalThread 应该停止它的最佳方法吗?也许我应该使用一些事件,它是在主线程中“返回”之后自动生成的,或者可能以某种方式检查主线程.IsAlive()还是我应该使用AppDomain.ProcessExit?
void main()
{
Thread.CurrentThread.Name = "MainThread";
Thread addThread = new Thread(DoSomething)
addThread.Name = "AdditionalThread";
addThread.IsBackground = false;
addThread.Start();
return 0;
}
DoSomething()
{
While( true || /* while mainthread is working */)
{
/* do something */
}
}
谢谢!