I've got the following code that I'm trying to use to trap Ctrl+C in a console app:
/// <summary>
/// A driver program for testing
/// </summary>
/// <param name="args">Arguments to the program</param>
static void Main(string[] args)
{
var program = new Program();
Console.Clear();
Console.TreatControlCAsInput = false;
Console.CancelKeyPress += program.OnCancelKeyPress;
program.Run(args.FirstOrDefault() ?? "3.26.200.125");
Console.WriteLine("Press any key to continue ...");
Console.ReadKey();
}
/// <summary>
/// Called when [cancel key press].
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.ConsoleCancelEventArgs"/> instance containing the event data.</param>
internal void OnCancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
this.Continue = false;
e.Cancel = true;
}
I've already checked the questions here and here, but for some reason, when I press Control+C, Visual Studio 2010 won't get into my handler in the debugger, I just get a 'source code unavailable' screen, and the opportunity to continue debugging, and that's it. Does anybody have any idea why I'm not getting into the handler ? I'm sure I'm just missing something simple.