开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜