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