我有个函数,你可修改一下应用到自己的程序
function TfrmMsg.ChkThreadAlive: boolean;
var
dwExitCode: DWORD;
fprocessExit: boolean;
begin
// memo1.Lines.Add('enter chkthreadalive');
Result := False;
dwExitCode := 0;
// fprocessExit := false;
//******** ComThd 为一线程 *********
if not Assigned(ComThd) then
Exit;
fprocessExit := GetExitCodeThread(ComThd.Handle, dwExitCode);
if (fprocessExit and (dwExitCode <> STILL_ACTIVE)) then
begin
Memo1.Lines.Add('ComThd 线程终止');
CloseHandle(ComThd.Handle);
Exit;
end;
Result := True;
end;