Debugger.Launch 和 Debugger.Break 之间的区别
有什么区别
Debugger.Launch();
Debugger.Break();
?
What's the difference between
Debugger.Launch();
Debugger.Break();
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
阅读文档后,如果附加了调试器,听起来
Launch
不会执行任何操作 - 它实际上不会中断(尽管我尚未验证这一点)。Break
要求启动调试器(如果未附加),并且执行进行中断。实际上,您不太可能拥有多个
启动
点...如果是的话。Reading the documentation, it sounds like
Launch
does nothing if the debugger is attached - it doesn't actually break (although I haven't verified this).Break
asks to launch the debugger (if not attached), and does do the break.In reality, it is unlikely you'd have more than one
Launch
point... if that.当调试器可用时,Launch 将启动调试器。但如果没有可用的,则被忽略。如果没有可用的调试器,Break 将使程序崩溃。
Launch will start a debugger when one is available. But is just ignored if there is none available. Break will crash the program if no debugger is available.
更细微的区别:
如果已附加调试器,则 Debugger.Launch 是 nop;然而
Debugger.Break
总是会中断进入调试器。
推出
调试器实际上并没有中断
进入调试器。例如,在
Visual Studio,
Debugger.Launch
将附加一个调试器到正在运行的进程,但是
那么你还需要进行 Debug |
在 Visual Studio 中进行真正的破解
调试器。
More subtle differences:
If a debugger is already attached, Debugger.Launch is a nop; whereas
Debugger.Break
will always breakinto the debugger.
Launching a
debugger does not actually break
into the debugger. For example, in
Visual Studio,
Debugger.Launch
will attach adebugger to the running process, but
then you still need to do a Debug |
Break in Visual Studio to actually break under
the debugger.
我不确定是否有人真正尝试过 .NET Framework 和 .NET 5 之间有什么区别或者是否不同,但这是我测试它时的行为:
单击“确定”后,VS 将在 < code>Debugger.Launch() (尽管其他回答者说不会):
但是,调试器不会在
Debugger.Launch() 上中断
(如果已附加)。如果我将项目打包为 dotnet 工具,除了不知道在哪里中断之外,一切都是一样的:
TL;DR: 在 .NET 5 中:
附加调试器:
.Launch()
将不执行任何操作.Break()
将在未附加调试器的情况下中断:
.Launch()
将要求附加调试器,如果如果你这样做,它将在.Launch()
处中断.Break()
将不执行任何操作(无例外)Example.csproj:
Program.cs:
I'm not sure if anyone actually tried what's the difference or if it's different between .NET Framework and .NET 5 but this is the behavior when I test it:
After clicking OK VS will break on
Debugger.Launch()
(despite other answerers saying it will not):However the debugger will not break on
Debugger.Launch()
if it is already attached.If I pack my project as a dotnet Tool everything is the same except it doesn't know where to break:
TL;DR: In .NET 5:
With debugger attached:
.Launch()
will do nothing.Break()
will breakWithout debugger attached:
.Launch()
will ask to attach a debugger and if you do, it will break at.Launch()
.Break()
will do nothing (no exceptions)Example.csproj:
Program.cs: