关闭 .NET 控制台应用程序时会发生什么?
是否调用了诸如 OnClosed(EventArgs e)
之类的方法?
更新
最终使用以下网址中的代码:
http://osdir.com/ml/windows.devel.dotnet.clr/2003-11/msg00214.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看这篇文章/帖子。
本质上,您连接 SetConsoleCtrlHandler 并订阅事件。
Take a look at this article/post.
Essentially, you hook up with the SetConsoleCtrlHandler and subscribe to the events.
不,因为没有用于关闭事件的消息泵。
但是,当进程被拆除时,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.
有
AppDomain.ProcessExit
< /a> 您可以将事件处理程序连接到的事件。注意认为它是“时间限制的”;默认情况下,它最多允许执行 3 秒,因此您不应该在其中执行任何耗时的操作。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.