Re: [twsocket] processmessages or messagepump
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. 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
Re: [twsocket] processmessages or messagepump
Why don't you write your own message pump with GetMessage? This way you can process your custom messages as well. Regards, SZ On Fri, Jul 18, 2008 at 10:08 AM, info2004 [EMAIL PROTECTED] 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. 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 -- 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
Re: [twsocket] processmessages or messagepump
Francois PIETTE wrote: So in execute is it Ok to: 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. You can use this to overcome sleep : // If there are messages in the queue, then do not wait at all, else, wait // as little as possible, so as to avoid 100% CPU usage and still process // as fast as we possibly can. MsgWaitForMultipleObjectsEx(0, pHandles, 1, QS_ALLINPUT, MWMO_ALERTABLE); Obviously, one has to understand message processing in the first place... -- 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
Re: [twsocket] processmessages or messagepump
info2004 wrote: How would I implement a timeout? Do I create a timer component within the thread, or is there a more elegant solution? A timer is ok since your thread processes messages already :-) You could, for example, use an integer that is incremented in timer's event handler and reset it to zero when TWSocket receives something. In the timer event handler check that integer. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -- 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