procedure FreeThread(_Thread: TThread);
var
i: Integer;
iExitCode: Cardinal;
begin
iExitCode := 0;
with _Threaddo
try
...
for i := 1 to 20do
//等待线程退出
begin
GetExitCodeThread(Handle, iExitCode);
//查询线程状态
if iExitCode = STILL_ACTIVE then
Sleep(100)
else
break;
end;
if iExitCode = STILL_ACTIVE then
TerminateThread(Handle, iExitCode);
//强制结束线程
finally
Free;
end;
end;