info2004 wrote:
> Francois, and Arno,
>
>>> while not terminated do
>>> begin
>>> WSocket.MessagePump;
>>> // check if I need to do something
>>> sleep(100);
>>> end;
>>> // close it all down
>>> Or am I missing the point in the use of the message pump?
>>
>> Yes, you miss something. The code you've done will be very slow at
>> processing events because of the sleep. And it you remove the sleep,
>> it will use all CPU.
> OK.
>>
>> The solution is simple: you need to use a real message loop. Easy:
>> just call MessageLoop which all TWSocket instances have. To
>> terminate the message loop, you can post a WM_QUIT message when you
>> detect your thread has terminated.
>
> If I do:
> while not terminated do
> begin
> WSocket.MessageLoop;
> // check if I need to do something
> end;
> // close it all down
>
> Then my understanding from what you have said is that I only get to
> the // check if I need to do something
>
> when a quit is posted.
>
> I am running a finite state machine in the execute loop, which
> marshalls responses, checks timeouts etc. If I don't exit the message
> loop, I can't do this.
1) Rely on WSocket events, control program flow from the various
event handlers.
2) In order to control your thread or anything else you can use
your own custom messages (WM_USER + n) and run your own custom
message loop, here's an example:
procedure MyMessageLoop;
var
Msg : TMsg;
begin
while GetMessage(Msg, 0, 0, 0) do
begin
if Msg.hwnd = 0 then
// Messages posted with PostThreadMessage() go here,
// their Hwnd equals zero.
begin
case Msg.message of
WM_CUSTOM_MESSAGE_1: DoSomething1;
WM_CUSTOM_MESSAGE_2: DoSomething2;
else
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end
else begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
end;
--
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
> Really sorry if I am missing the point on this. Long hours, fried
> brain.
>
> Regards,
>
> Andy
>>
>> --
>> [EMAIL PROTECTED]
>> The author of the freeware multi-tier middleware MidWare
>> The author of the freeware Internet Component Suite (ICS)
>> http://www.overbyte.be
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be