-6ren">
gpt4 book ai didi

c# - 防止 Visual Studio 调试在明显的 "unhandled exception"上中断

转载 作者:太空狗 更新时间:2023-10-29 21:55:24 25 4
gpt4 key购买 nike

请考虑这个简短的控制台应用程序代码。

static void Main(string[] args)
{
try
{
Action a = () =>
{
throw new ApplicationException("Oops");
};

var ar = a.BeginInvoke(null, null);
ar.AsyncWaitHandle.WaitOne();
try
{
a.EndInvoke(ar);
Console.WriteLine("No message");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
finally
{
Console.ReadKey();
}
}

当运行 Visual Studio 时,throw 会中断并提示未处理。当在调试器外部执行时,代码会按照我的预期执行(显示“糟糕”)。

我如何说服 Visual Studio 允许代码像在现实世界中一样执行?

最佳答案

您可以申请 DebuggerNonUserCode attribute到一种方法以将其隐藏在调试器中。

关于c# - 防止 Visual Studio 调试在明显的 "unhandled exception"上中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7685107/

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