怎样判断一个线程正在执行?(6分)

  • 主题发起人 panjigan
  • 开始时间
P

panjigan

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样判断一个线程正在执行?我想中止它
 
if thA.ThreadId<>0 then
thA.Terminate;
 
我有个函数,你可修改一下应用到自己的程序
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;
 
在主线程里用变量记录线程的状态!
然后在释放!
 
多人接受答案了。
 
顶部