本文整理自网络,侵删。
delphi 主线程等待一个 无阻塞函数 死循环子线程的安全退出子线程:
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;
相关阅读 >>
Delphi 使用onvalidate事件或onvalidating事件验证在输入字段(tedit)中输入的值
Delphi simple resource api replacement
Delphi clipboard 截图后将图片数据复制到剪贴板
Delphi trayicon控件,如何实现窗口最小化的时候到系统托盘?
Delphi combobox1dropdown 生成动态下拉列表
更多相关阅读请进入《Delphi》频道 >>