views:

61

answers:

1

Hey everyone,

I'm working on a project that calls a console window to process some data based on passed in arguments. What I would like to know is how I can check to see if the user clicked on the red X within the console app. Is there an event I need to handle? Any advice would be greatly appreciated. This is being done using the .NET framework 3.5 using VS2005. Thanks.

+2  A: 

Use SetConsoleCtrlHandler, C# example here.

Ben Voigt
This is a great start to what I need. However, how would I be able to modify the return code for this. Example :private static bool ConsoleCtrlCheck(CtrlTypes ctrlType){ // Put your own handler here switch (ctrlType) { case CtrlTypes.CTRL_CLOSE_EVENT: { //TODO: Be able to set a custom return code that the program can return. } } return true;}
Seb
You can set your process exit code by calling `Environment.Exit` http://msdn.microsoft.com/en-us/library/system.environment.exit.aspx
Ben Voigt
Thank you so much for the information :)
Seb