Internet Direct (Indy) Version 9.0.2 Beta
TIdTCPServer.OnDisconnect
Event handler for peer thread disconnection.

property OnDisconnect: TIdServerThreadEvent;
Description
OnDisconnect is an event handler for a TIdServerThreadEvent event, and occurs when the TIdPeerThread attempts to disconnect from a TCP server. OnDisconnect receives the parameter AThread, and represents the TIdPeerThread thread requesting to be disconnected. OnDisconnect is triggered when Athread has finished execution, and just prior to the TIdPeerThread being released by the thread manager specified in ThreadMgr.

Note: Do not call Synchronized method in the OnDisconnect event handler. Only inherited Notification calls are safe for use in OnDisconnect.

This is important because OnDisconnect is called for active client threads when the server sets Active to False. Using synchronized methods in OnDisconnect can result in a deadlock condition, caused when the thread is suspended while the method is executing in the main VCL thread.

TIdTCPServer will detect the deadlock condition, but a timeout error will be raised while trying to terminate the active threads. Use Thread.Notification to act on the notification that a component is being inserted or removed. For example, if a component has object fields or properties that contain references to other components, it can check the notifications of component removals and invalidate those references as needed.

Assign a TIdServerThreadEvent event handler procedure to OnDisconnect to allow responding to the event notification.