public static class ConsoleHelper
{
private const int CTRL_CLOSE_EVENT = 2;
public delegate bool ConsoleCtrlDelegate(int dwCtrlType);
[DllImport("kernel32.dll")]
private static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate HandlerRoutine, bool Add);
private static bool HandlerRoutine(int CtrlType)
{
switch (CtrlType)
{
case CTRL_CLOSE_EVENT:
break;
}
return false;
}
public static void SetHandler()
{
ConsoleCtrlDelegate newDategate = HandlerRoutine;
SetConsoleCtrlHandler(newDategate, true);
}