title: Stop a .net console app from being closed
body: <p>Is there any way to stop a .NET console app from being closed? I've got an app that follows this pattern:</p>
  
  <pre><code>while (true)
  {
      string x = Console.ReadLine();
      StartLongRunningTaskOnSeparateThread(x);
  }
  </code></pre>
  
  <p>The problem is that it's possible to close the console window (and therefore cut off the long running task). Is there an equivilent of the Forms.OnClosing event for console apps?</p>
  
  <p>EDIT - I'm not trying to create something that's impossible to kill, just maybe give a warning message e..g "hey i'm not done yet. are you sure you want to close me?"</p>
  
  <p>EDIT2 - Preventing an untimely exit via the 'x' button is more important than blocking Ctrl-C (I used <code>Console.TreatControlCAsInput = true;</code>). Assume for this purpose that anyone who fires up task manager wants to kill the program so much that they deserve to be able to. And that the end user would rather see a warning than accidentally cancel their long running task. </p>