public void threadMethod()
{
try
{
// do something
}
catch (ThreadInterruptedException e)
{
Console.WriteLine("[Net]", role, "Thread interrupted.");
n.CloseConnection();
}
finally
{
if (isAutenticated == false)
{
n.CloseConnection();
}
Dispatcher.Invoke(addMessage, "Network connection searching was disabled.");
DebuggerIX.WriteLine("[Net]", role, "Finished");
Dispatcher.Invoke(threadStoppedDel);
}
}
方法threadMethod通过System.Threading.Thread运行。线程可能会被中断,因此可能会在 finally 块中抛出异常ThreadInterruptedException ,对吗?我是否必须再次将块包含在 try-catch 中?
谢谢!