I always showed such things in the main thread and used events to synchronize the end of the window with the stream, to tell him when the windows are closed.
Today during development, I wanted to move the displayed form from the stream to the main user interface, but it was successfully displayed. The only thing I added is that in the main thread I click on messages waiting for events:
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;
So my question. Is such a scenerio acceptable? Or should I move the form to display in the main thread?
thank
source
share