Indy servers are multi-threaded. Their events (like OnConnect
, OnDisconnect
, OnExecute
, OnException
, and OnListenException
) are triggered in the context of worker threads, not the context of the main UI thread. As such, you must sync with the main thread, such as with the TThread.Synchronize()
or TThread.Queue()
methods, or Indy's TIdSync
or TIdNotify
classes, in order to access UI components safely.
If the main thread is busy deactivating the server, it cannot process sync requests, so an asynchronous approach (TThread.Queue()
or
TIdNotify
) is preferred over a synchronous one (TThread.Synchronize()
or TIdSync
) to avoid a deadlock. Alternatively, deactivate the server in a worker thread so the main thread is free to process sync requests.