0
votes

Good day. I create a class instance Thread. In this thread I create udpserver. UDPREAD synchronizes with the main thread.

Question: How to synchronize not with the main thread but with the thread that is the parent of the UDP

thank you

1

1 Answers

1
votes

TIdUDPServer is a multi-threaded component. Internally, it runs a separate reading thread for each item that you setup in the TIdUDPServer.Bindings collection. When a given Binding receives incoming data, the corresponding thread reads the data and then fires the OnUDPRead event.

By default, the OnUDPRead event handler is called in the context of the main UI thread, via a call to TThread.Synchronize(). If you want to avoid that, you need to set the TIdUDPServer.ThreadedEvent property to true. The event handler will then be called in the context of the Binding's reading thread directly, and you can synchronize your event handler's code with your server's parent thread however you want.