TsgcQUICServer › Events › OnShutdown
Fires when the server has stopped listening and released its resources.
property OnShutdown: TNotifyEvent;
// TNotifyEvent = procedure(Sender: TObject) of object
—
OnShutdown is published and inherited from the UDP server base class, and the QUIC server raises it at the end of the teardown. So when the handler runs, the listener thread has already been terminated, every connection has been released and the SSL context has been freed.
It is raised from Stop (equally from Active := False, which is what Stop does), on the caller's thread, before Stop returns. It is also raised when a running server is destroyed, because the destructor tears the listener down.
Only a server that was actually listening raises it. Stopping an already stopped server, or destroying one that was never started, is silent, so the handler runs at most once per successful OnStartup and you can pair the two safely.
In the .NET implementation OnShutdown is raised at the end of Stop(), and also when the server is disposed, so a handler behaves the same in both languages.
// Raised once the listener and every connection have been released:
procedure OnShutdown(Sender: TObject);
begin
WriteLn('#QUIC server stopped');
end;
// Assign it before starting the server
oServer.OnShutdown := OnShutdown;
...
oServer.Stop; // raises OnShutdown, a second Stop stays silent