title: Why does adding a Console.CancelKeyPress handler block debugger CTRL+C exit when a Task is running
body: <p>I have managed to get this down to a minimal test case running in VS2017 with .Net Framework 4.6:</p>
  
  <pre><code>    static void Main(string[] args)
      {
          Console.CancelKeyPress += (o, e) =&gt; End(); //some attempt to exit gracefully
          Task.Run(() =&gt; Task.Delay(100000)).Wait();
      }
  
      private static void End()
      {
          Console.WriteLine("EXITING...");
      }
  </code></pre>
  
  <p>If I run this in the debugger with <code>Console.CancelKeyPress</code> commented out, CTRL+C force-terminates the application. With the code as written, it outputs "EXITING..." then hangs even though my event handler does nothing to prevent termination.</p>
  
  <p>If I run from the command line, both versions exit as expected.</p>
  
  <p>It took me some time to figure out the unfinished <code>Task</code> is involved but I have no idea why the event handler is changing the behaviour. Can anyone figure out why? Is it some debugger quirk? I see no errors in the debugger...</p>