"退出"控制台应用程序控制台、应用程序、QUOT

2023-09-02 10:24:49 作者:素未谋面你算老几

我要寻找一种方式来触发一张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.

http://geekswithblogs.net/mrnat/archive/2004/09/23/11594.aspx

掌握控制台退出C#