关闭 .NET 控制台应用程序时会发生什么?

发布于 2024-08-06 19:05:31 字数 286 浏览 2 评论 0 原文

是否调用了诸如 OnClosed(EventArgs e) 之类的方法?

更新

最终使用以下网址中的代码:

http://osdir.com/ml/windows.devel.dotnet.clr/2003-11/msg00214.html

Is a method such as OnClosed(EventArgs e) called?

Update

Ended up using code from the following url:

http://osdir.com/ml/windows.devel.dotnet.clr/2003-11/msg00214.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

懷念過去 2024-08-13 19:05:31

看看这篇文章/帖子

本质上,您连接 SetConsoleCtrlHandler 并订阅事件。

Take a look at this article/post.

Essentially, you hook up with the SetConsoleCtrlHandler and subscribe to the events.

咋地 2024-08-13 19:05:31

不,因为没有用于关闭事件的消息泵。

但是,当进程被拆除时,AppDomain 会被卸载,这将触发 AppDomain.DomainUnloaded。您可以使用它来捕获程序关闭时的事件。

No, since there is no message pump for a close event.

However, the AppDomain is unloaded as the process is torn down, and this will fire AppDomain.DomainUnloaded. You can use that to trap an event as the program shuts down.

烟凡古楼 2024-08-13 19:05:31

There is the AppDomain.ProcessExit event that you could hook up an event handler to. Note thought that it is "time boxed"; by default it is allowed to execute for a maximum of 3 seconds, so you should not do anything time consuming in there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文