C# Console Applications and Ctrl-C

11. August 2008 09:41 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

Console applications are still very useful for me.
I write like 125 console applications in the morning and like 4 or 5 in the afternoon.
In one of these applications that was running a long process I just started wandering:
what will happen with Lost? Will ABC ever finish this series?
And If someone presses Ctrl-C will I be able to catch it?
And indeed, the greate C# provides a very easi way to do it:

 static void Main(string[] args)
            Console.CancelKeyPress += 
            delegate(object sender, ConsoleCancelEventArgs e)
                Console.WriteLine("Process aborted by user!");
            //Long running process