您的位置:首页 > 其它

主线程等待一个 无阻塞函数 死循环子线程的安全退出

2013-04-28 12:47 246 查看
子线程:

procedure TreadThread.Execute;
begin
inherited;
FreeOnTerminate := True;
while not Terminated do begin
////dosomething;
end;
Sleep(100);
end;
end;

主线程:

var
H: array[0..0] of Thandle;
begin
try
H[0] := RCThread.handle;

// 安全退出子线程
RCThread.Terminate;
if MsgWaitForMultipleObjects(1, H, True, 1000, QS_ALLINPUT) = WAIT_OBJECT_0 then begin
//线程已经安全退出
end;
except
on e: Exception do
ShowMessage(e.Message);
end;
end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐