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.
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
Capture console exit C#