0

I need to cancel closing with ALT+F4, CTRL+C, CTRL+Break.

I canceled CTRL+C and CTRL + break using 
Console.CancelKeyPress += delegate (object? sender, ConsoleCancelEventArgs e) {
            e.Cancel = true;
   
        };
but my program still closing after ALT+F4
 How can i fix that?
RodyaHjilz
  • 13
  • 1
  • What operating system? [This answer](https://stackoverflow.com/a/71185511/10601203) explains how to do it in Windows by changing the registry, but this will likely apply to all console applications you run, not just the one you're creating. Since your program doesn't actually own the console window, your program won't receive any notice when this happens so you can't do it with events. – Jesse Dec 07 '22 at 20:43
  • Welcome to SO. This might have some answers: https://stackoverflow.com/questions/14943/how-to-disable-alt-f4-closing-form – Vic F Dec 07 '22 at 22:31
  • @VicF That's for forms not console applications. As I mentioned before, console applications don't own the console window, it's just an instance of the command prompt. WinForms/WPF does own their windows, so they can handle exit events on their own. – Jesse Dec 07 '22 at 23:53

0 Answers0