2012/9/5 Michael Schnell <[email protected]>: > On 09/05/2012 11:35 AM, Antonio Fortuny wrote:
> IMHO it's easy and straight-forward to use TApplication.QueueAsyncCall() for > this. I have recently implemented something that has one network thread (using LNet and events that are fired and running from within this network thread) and once they have received a complete protocol message from the network they instantiate and enqueue one of my TMsgXxxx (my own proprietary classes of messages) into a thread safe queue and then wake up the main thread who will then pop messages from the queue and execute them from within the main thread. My message classes all implement an Execute() method, the Execute() method will be called from the main thread once it has popped the message from the queue and can interact with the gui. This was a lot of infrastructure code but it works nicely and I can use this message queue also for other messages that need to be sent to the GUI, not only network messages, I can essentially send a piece of code along with data to the gui for later execution. the complete code is here: https://github.com/prof7bit/TorChat/tree/torchat2/src/core TLTcp server, the eventer an the event thread is initialized in tc_client.pas TLTcp clients are created in tc_buddy.pas (they are using socks4a to connect), incoming data is parsed and and enqueued in tc_conn.pas the queue and message base classes are in tc_msgqueue.pas and tc_protocol.pas and then there are a lot of protocol messages that implement my IProtocolMessage interface and are able to do funny things from within the main thread in their Execute() method. The entry point for the GUI thread is the Pump() method of TTorChatClient, this will pop the next message, execute it, check a few timeouts and then immediately return. -- _______________________________________________ Lazarus mailing list [email protected] http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
