【发布时间】:2010-09-18 18:45:21
【问题描述】:
我的应用程序有几个线程: 1) 主线程 2)2个子主线程(每个都有Message Loop,如下图),TFQM使用 3)n个工作线程(简单循环,包含Sleep())
我的问题是,当我关闭我的应用程序时,工作线程设法正确退出,但是当我发出 WM_QUIT 关闭它们时,2 个子主线程中的 1 个挂起(从不退出)。
procedure ThreadProcFQM(P: Integer); stdcall;
var
Msg: TMsg;
_FQM: TFQM;
begin
_FQM := Ptr(P);
try
_FQM.fHandle := AllocateHwnd(_FQM.WndProc);
while GetMessage(Msg, 0, 0, 0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
finally
DeallocateHWnd(_FQM.fHandle);
SetEvent(_FQM.hTerminated);
end;
end;
procedure TFQM.Stop;
begin
PostMessage(fHandle, WM_QUIT, 0, 0);
WaitForSingleObject(hTerminated, INFINITE);
if hThread <> INVALID_HANDLE_VALUE then
begin
CloseHandle(hThread);
hThread := INVALID_HANDLE_VALUE;
end;
end;
【问题讨论】:
标签: multithreading delphi winapi