title: Calling Thread.Abort on a thread from a ThreadPool
body: <p>My co-worker is using a third-party .NET library for which we don't have the source code.  We're using a ThreadPool to have a lot of threads call into this library, and occasionally one of the threads will just hang forever while the rest of them merrily chug along.</p>
  
  <p>So we want to use the dreaded <code>Thread.Abort</code> to kill such threads.  I've done this before when spinning up my own threads, but I've never used a ThreadPool.  If we track the start times of each task like this:</p>
  
  <pre><code>static Dictionary&lt;Thread, DateTime&gt; started = new Dictionary&lt;Thread, DateTime&gt;();
  
  static void DoSomeWork(object foo)
  {
      lock(started)
          started[Thread.CurrentThread] = DateTime.Now;
  
      SomeBuggyLibraryThatMightInfiniteLoopOrSomething.callSomeFunction(doo);
  
      lock(started)
          started.Remove(Thread.CurrentThread);
  }
  </code></pre>
  
  <p>then can we lock and iterate over the running threads and call <code>Thread.Abort</code> to kill them?  And if we do, then will we need to add a new thread to the ThreadPool to replace the one that we just killed, or will the ThreadPool handle that for us?</p>
  
  <p>EDIT: I'm very aware of all of the potential problems with <code>Thread.Abort</code>.  I know that it should ideally never be used in production code, and that it doesn't necessarily even stop the thread, and that if you abort a thread while the thread has acquired a lock, then you can hang up other threads, etc.  But right now we're on a tight deadline and we have decent reason to believe that in this one particular case, we can call <code>Thread.Abort</code> without putting the entire process in jeopardy, and we'd like to avoid rewriting this program to eliminate the ThreadPool unless we absolutely have to.</p>
  
  <p>So what I want to know is this: given that we WILL be calling <code>Thread.Abort</code> on a thread that belongs to a ThreadPool, are there any special problems caused by these being ThreadPool threads, and do we have to manually spin up a new thread to replace the one that got killed or will the ThreadPool do that for us?</p>