I have the following code that I am trying to use to capture Ctrl + C in a console application:
/// <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 already checked the questions here and here , but for some reason, when I press Control + C, Visual Studio 2010 will not get into my handler in the debugger, I just get the "inaccessible source code" screen and the ability to continue debugging and what it is. Does anyone know why I didn't hit the handler? I'm sure I just missed something simple.
source share