Control-Break in C# console application
-
Hello, I've written a small console application for me and some collegues to use, it contains a lot of commands, all of which we use on a daily basis. To prevent also having to open a windows commandprompt besides my own console, i also included the ping command in my console (started with a process.start) and the results are written in my console. All good and well, but when i keep pinging (ping hostname /t) i have to be able to use ctrl-c and ctrl-break without my console exiting. So i implemented the following in my code:
static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
if (e.SpecialKey == ConsoleSpecialKey.ControlC)
{
e.Cancel = true;
}
else
{
//e.Cancel = true; throws an error
dowhile();
}
}the function dowhile() calls a function where i read the input as long as the user doesnt type "exit". I couldnt cancel the event when ctrl-break is pressed, so i guessed i should just call my dowhile function again. Everything works fine, except when i try to close my application typing exit, or pressing the close button. It takes 3 to 5 seconds before my console closes. This only happens when i pressed Ctrl-Break before. Am i doing something wrong, or is there a better way to prevent Ctrl-Break from exiting my console? My console just cant close when i press Ctrl-Break because then i can't see my temporary ping statistics anymore. Any thoughts? Thanks in advance.