// in Main
static void Main(string[] args) {
handler = new ConsoleEventDelegate(ConsoleEventCallback);
SetConsoleCtrlHandler(handler, true);
}
static bool ConsoleEventCallback(int iType) {
if (iType == 2) {
Console.WriteLine("удаляем лоадер");
}
return false;
}
static ConsoleEventDelegate handler;
private delegate bool ConsoleEventDelegate(int iType);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add);