【发布时间】:2011-04-15 03:08:45
【问题描述】:
我正在将一个线程初始化为静态线程,如下所示
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();
}
但是当我通过这个方法中止这个线程时
private void btnStop_Click(object sender, EventArgs e)
{
if (Test != null)
Test .Abort();
}
它给出了以下异常: " mscorlib.dll 中发生了“System.Threading.ThreadAbortException”类型的第一次机会异常 线程 0x13dc 已退出,代码为 0 (0x0)。 "
如何摆脱这个异常??
【问题讨论】:
-
它不是异常,只是来自调试器检测到异常的通知。这是正常的, Thread.Abort() 注入异常。不要不要解决这个问题。
标签: c# multithreading