我正在将线程初始化为静态线程,如下所示
Thread GenerateKeywords;
private void btnStart_Click(object sender, EventArgs e)
{
//Initializes the Test Thread
Test = new Thread(TestMethod);
//Sets the apartment state to Static
Test.SetApartmentState(ApartmentState.STA);
//Starts the GenerateKeywords Thread
Test.Start();
}
Run Code Online (Sandbox Code Playgroud)
但是当我通过这种方法中止这个线程时
private void btnStop_Click(object sender, EventArgs e)
{
if (Test != null)
Test .Abort();
}
Run Code Online (Sandbox Code Playgroud)
这是给以下异常:"类型'System.Threading.ThreadAbortException’出现在mscorlib.dll线程0x13dc的第一个机会异常已退出,代码为0(为0x0)."
如何摆脱这种异常?