Post

Console Event Handling

Someone sent me an IM asking if I knew of a way to handle the pressing of the close button on a console application. After a bit of research, I found a way (and some limitations). This required stepping outside of the Microsoft .NET Framework utilizing P/Invoke. This allowed me to capture the application close event (which is initiated via the close button, the close menu item or task manager) and when Windows is shutting down (the user logging off). You can read all about how to accomplish this here.

This post is licensed under CC BY 4.0 by the author.