DELPHI(델파이)
[Delphi] WaitForSingle을 이용한 쓰레드 종료
Jcoder
2020. 12. 4. 13:46
쓰레드가 돌고 있을 때 폼과 같이 종료하는 법.
Var
KillEvt: THandle;
procedure TForm5.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SetEvent(KillEvt);
end;
// 쓰레드 execute 안에
.
.
if WaitForSingleObject(KillEvt, 60000 * 1) = WAIT_OBJECT_0 then // 1분마다.
exit;
참고 MSDN : WaitForSingleObject function (synchapi.h) - Win32 apps | Microsoft Docs
WaitForSingleObject function (synchapi.h) - Win32 apps
Waits until the specified object is in the signaled state or the time-out interval elapses.
docs.microsoft.com
// pas 파일 가장 마지막에
Initialization
KillEvt := CreateEvent(nil, True, False, PChar('KillThread')); // 'killThread'는 프로그램마다 다르게 설정.
Finalization
CloseHandle(KillEvt);