Wie gewuenscht, mein Code:
Delphi-Quellcode:
function MAC_Thread(pml: PMachineList): DWORD; stdcall;
var
msg: TMsg;
begin
while True do
case MsgWaitForMultipleObjects(0, PDWORD(nil)^, False, 5000, QS_ALLEVENTS) of
WAIT_OBJECT_0:
if PeekMessage(msg, 0, 0, 0, PM_REMOVE) then
case msg.message of
SIGNAL_STOP:
begin
{$IFDEF DEBUGGING}
Writeln('MAC: Received STOP.');
{$ENDIF DEBUGGING}
Exit;
end;
else
DispatchMessage(msg);
end;
WAIT_TIMEOUT:
begin
{$IFDEF DEBUGGING}
Writeln('MAC: Timeout ... scanning for machines');
{$ENDIF DEBUGGING}
PostThreadMessage(pml^.Dispatcher, SIGNAL_MACLISTUPD, 0, 0);
end;
end;
result := 0;
end;
Es war tatsaechlich die Sache mit dem Entfernen aus der Queue. Uebrigens, ich bekomme bei 5sec einen Timeout!
Hier noch ein Workerthread:
Delphi-Quellcode:
function WorkerThread(x: Pointer): DWORD; stdcall;
var
msg: TMsg;
begin
while True do begin
if PeekMessage(msg, 0, 0, 0, PM_REMOVE) then
case msg.message of
SIGNAL_STOP:
begin
{$IFDEF DEBUGGING}
Writeln('WRK: Received STOP.');
{$ENDIF DEBUGGING}
Exit;
end;
SIGNAL_WRKSCANMAC:
begin
{$IFDEF DEBUGGING}
Writeln('WRK: Now scanning machine with index ', msg.wParam);
{$ENDIF DEBUGGING}
DispatchMessage(msg);
end;
else
DispatchMessage(msg);
end;
WaitMessage; // lay down to sleep ... until we receive a message
end;
result := 0;
end;