title: Unable to trap Ctrl+C in a C# console app
body: <p>I've got the following code that I'm trying to use to trap Ctrl+C in a console app:</p>
  
  <pre><code>    /// &lt;summary&gt;
      /// A driver program for testing 
      /// &lt;/summary&gt;
      /// &lt;param name="args"&gt;Arguments to the program&lt;/param&gt;
      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();
      }
  
      /// &lt;summary&gt;
      /// Called when [cancel key press].
      /// &lt;/summary&gt;
      /// &lt;param name="sender"&gt;The sender.&lt;/param&gt;
      /// &lt;param name="e"&gt;The &lt;see cref="System.ConsoleCancelEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
      internal void OnCancelKeyPress(object sender, ConsoleCancelEventArgs e)
      {
          this.Continue = false;
          e.Cancel = true;
      }
  </code></pre>
  
  <p>I've already checked the questions <a href="https://stackoverflow.com/questions/177856/how-do-i-trap-ctrl-c-in-a-c-sharp-console-app">here</a> and <a href="https://stackoverflow.com/questions/1679876/atexit-exit-delegate-in-c-sharp">here</a>, 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.</p>