title: How to kill a thread in C# effectively?
body: <p>I am not <a href="https://stackoverflow.com/questions/5034538/how-to-kill-a-c-sharp-thread">trying</a> to <a href="https://stackoverflow.com/questions/2900003/c-sharp-threads-abort">beat</a> a <a href="https://stackoverflow.com/questions/2251964/c-sharp-thread-termination-and-thread-abort">dead</a> <a href="https://stackoverflow.com/questions/1327102/how-to-kill-a-thread-instantly-in-c">horse</a>, <a href="https://stackoverflow.com/questions/1051838/killing-a-thread-c">honestly</a>. And I've read all the advice on thread killing, however, please consider the code.  It does the following:</p>
  
  <ol>
  <li>It starts a thread (via <code>StartThread</code> method)</li>
  <li>It calls the database looking for anything in the ServiceBroker queue.  Note the <code>WAITFOR</code> command - it means that it will sit there until there is something in the queue.  All this in <code>MonitorQueue</code> method.</li>
  <li><p>Kill the thread.  I tried <code>.Interrupt</code> - it seems to do absolutely nothing.  Then I tried <code>.Abort</code>, which should never be used, but even that did nothing.</p>
  
  <pre><code>Thread thxMonitor = new Thread(MonitorQueue);
  void StartThread() {
      thxMonitor.Start();
  }
  
  void MonitorQueue(object obj) {
      var conn = new SqlConnection(connString);
      conn.Open();
      var cmd = conn.CreateCommand();
      cmd.CommandTimeout = 0; // forever and ever
      cmd.CommandType = CommandType.Text;
      cmd.CommandText = "WAITFOR (RECEIVE CONVERT(int, message_body) AS Message FROM SBQ)";
  
      var dataTable = new DataTable();
      var da = new SqlDataAdapter(command);
  
      da.Fill(dataTable);
      da.Dispose();
  }
  
  void KillThreadByAnyMeansNecessary() {
      thxMonitor.Interrupt();
      thxMonitor.Abort();
  }
  </code></pre></li>
  </ol>
  
  <p>Is it actually possible to kill a thread?</p>