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を介して実行されます。スレッドはいつでも中断される可能性があるため、例外ThreadInterruptedExceptionが finally ブロックでスローされる可能性がありますよね? ブロックを最後に try-catch で再度囲む必要がありますか?
ありがとう!