Will main thread catch exception thrown by another thread?
If I have code like this:
try
{
Thread t = new Thread(new ThreadStart(wc.LocalRunProcess));
t.IsBackground = true;
t.Start();
}
catch (Exception ex)
{
//do something with ex
}
Will the exception thrown by thread t
be cau开发者_JAVA技巧ght in the catch block?
No. It will not catch any exceptions in your other thread t
. You will have to catch them in that thread and deal with them appropriately.
However, I believe the AppDomain's UnhandedException event will report it.
Take a look at System.ComponentModel.BackgroundWorker! It has exception and cancellation handling.
精彩评论