ArtinSoft's Blogs

Software Migration Experts
Welcome to ArtinSoft's Blogs Sign in | Join | Help
in Search

Mauricio Rojas Blog

C# Console Applications and Ctrl-C

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)
            {
                Artinsoft.VBUMKernel.Implementations.UpgradeCommand.StopAllUpgradeProcess(true);
                Console.WriteLine("Process aborted by user!");
            };
            //Long running process
        }

Comments

 

egbsystems said:

Nice Post. Thanks for sharing

September 9, 2008 3:50 AM
Powered by Community Server (Non-Commercial Edition), by Telligent Systems