我一直在主线程中显示这些东西,并使用事件将窗口的结束与线程同步,让它知道窗口何时关闭。
今天,在开发过程中,我想将显示的表单从线程移动到主 UI,但它成功显示了。我唯一添加的是在主线程中我正在推送等待事件的消息:
procedure WaitWithMessageLoop();
var
vWaitForEventHandles:array[0..1] of THandle;
vWaitForResponse:DWORD;
Msg: TMSG;
begin
vWaitForEventHandles[0] := LServiceMonitor.Handle;
while (1=1) do
begin
vWaitForResponse := MsgWaitForMultipleObjects(1, vWaitForEventHandles, FALSE, INFINITE, QS_ALLINPUT);
if (vWaitForResponse = WAIT_OBJECT_0 + 1) then
begin
while (PeekMessage(msg,0,0,0,PM_REMOVE)) do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
end
else
if (vWaitForResponse = WAIT_FAILED)
then RaiseLastOSError
else break;
end;
end;
所以我的问题是。这样的场景可以接受吗?或者我应该移动一个表单以显示在主线程中吗?
谢谢