1

In the Visual Studio environment, I noticed two different end behaviors in my program while debugging. When I would press the Stop Debugging button while my program is still running I experienced a different behavior than when I actually close the form by clicking on the top right red X which also stops debugging. I always thought they did the same thing, but for my program, I am experiencing different end conditions. Can anyone tell me if there really is a difference between these two methods of ending debugging.

Stop Debugging Button

Closing the Form

4

2 回答 2

4

当然,差别很大。单击窗口的关闭按钮将启动您的应用程序的受控关闭,从触发 FormClosing 事件开始。如果它是您的应用程序的主窗口,Application.Run() 在您的 Main() 方法中返回,Main() 方法返回并结束您的 UI 线程。如果没有更多非后台线程,则 CLR 以受控方式关闭,运行所有剩余的终结器,卸载 AppDomain 并结束进程。

使用调试器的停止调试命令是一个即时粗鲁的过程中止。 根本没有代码运行,无论是在您的程序中还是在 CLR 中。砰!超过。

于 2013-08-05T20:22:26.710 回答
1

关闭表单将遵循任何或所有关闭事件。停止调试器会立即终止程序。

于 2013-08-05T20:16:51.963 回答