title: Delphi: Kill threads when application quits?
body: <p>Background: I need to perform checks whether a bunch of network drives or remote computers are available. Since each <code>DirectoryExists()</code> needs a lot of time until a potential timeout, I perform the checks in separate threads. It can happen, that an end-user closes the application while some of the checks are still running. Since <code>DirectoryExists()</code> blocks, I have no chance of using the classical <code>while not Terminated</code> approach.</p>
  
  <pre><code>procedure TMyThread.Execute;
  begin
    AExists := DirectoryExists(AFilepath);
  end;
  </code></pre>
  
  <p>Question 1: Is it a problem that some threads are still running when the application quits? Will Windows simply tidy up after me and that's it? Inside the IDE I get notification of un-freed objects, but outside IDE it just appears to be peaceful.</p>
  
  <p>Question 2: Is it possible to terminate such simple threads with <code>TerminateThread</code> or is this potentially harmful in THIS case? </p>
  
  <p>Question 3: I usually take the results from the threads in <code>OnTerminate()</code> event and let the threads <code>FreeOnTerminate</code> afterwards. If I wanted to free them myself, when should I do it? Can I free a thread in its <code>OnTerminate</code> event or is this a tiny bit too early? How would a thread inform me that it is done if not with <code>OnTerminate</code>?</p>