"退出"控制台应用程序 [英] "On Exit" for a Console Application

查看:246
本文介绍了"退出"控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方式来触发一张code,当一个控制台应用程序被手动关闭(用户关闭窗口)。一直试图用:

I am looking for a way to trigger a piece of code when a console application is manually closed (users closes window). Been trying with:

AppDomain.CurrentDomain.ProcessExit +=
    new EventHandler(CurrentDomain_ProcessExit);

但如果手动关闭上述不起作用。

but the above doesn't work if manually closed.

有没有使用的.Net呼吁这还是我需要导入的内核DLL和这样做的什么方法?

Is there any ways to use a .Net call for this or do I need to import the Kernel dll and do it that way?

推荐答案

您需要连接到控制台退出事件,而不是你的进程。

You need to hook to console exit event and not your process.

<一个href="http://geekswithblogs.net/mrnat/archive/2004/09/23/11594.aspx">http://geekswithblogs.net/mrnat/archive/2004/09/23/11594.aspx

掌握控制台退出C#

这篇关于&QUOT;退出&QUOT;控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆