gpt4 book ai didi

c# - 主线程会捕获另一个线程抛出的异常吗?

转载 作者:IT王子 更新时间:2023-10-29 04:49:12 25 4
gpt4 key购买 nike

如果我有这样的代码:

try
{
Thread t = new Thread(new ThreadStart(wc.LocalRunProcess));
t.IsBackground = true;
t.Start();
}
catch (Exception ex)
{
//do something with ex
}

线程t抛出的异常会在catch block 中被捕获吗?

最佳答案

没有。它不会在您的其他线程 t 中捕获任何异常。您必须在该线程中捕获它们并适本地处理它们。

但是,我相信 AppDomain 的 UnhandedException 事件会报告它。

关于c# - 主线程会捕获另一个线程抛出的异常吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4962769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com