相关疑难解决方法(0)

为什么后台线程中未处理的异常不会导致应用程序域崩溃?

我完全不解.如果在我从未测试过的线程中存在未捕获的异常,我非常确定.NET会关闭整个应用程序域.

但是我只是尝试了下面的代码并且它没有失败......任何人都可以解释为什么?

(在.NET 4和3.5中尝试过)

static void Main(string[] args)
{
    Console.WriteLine("Main thread {0}", Thread.CurrentThread.ManagedThreadId);

    Action a = new Action(() =>
    {
        Console.WriteLine("Background thread {0}", Thread.CurrentThread.ManagedThreadId);

        throw new ApplicationException("test exception");
    });

    a.BeginInvoke(null, null);

    Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading delegates exception-handling

15
推荐指数
2
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

delegates ×1

exception-handling ×1

multithreading ×1