ServiceApplication.Stop
From Xojo Documentation
Event
Occurs in two situations: When the user selects Stop from the Service Control Manager on Windows or when the computer is shutting down.
Notes
If the user selected Stop, ShuttingDown is False.
If the computer is shutting down, ShuttingDown is True. This event occurs when you call the Quit method on any platform or when the service terminates. The ShuttingDown parameter is supported only on Windows.