Indy 9
Example
IsCurrentThread
  if IsCurrentThread(AThread) then
    AThread.FreeOnTerminate := True
  else begin
    AThread.TerminateAndWaitFor;
    AThread.Free;
  end;

Created with Doc-O-Matic 2 donated to Project JEDI. Commercial license available from the Doc-O-Matic site.