You must use the ControlService () function to stop the service, and then return from the program flow, if this should also lead to the completion of the process.
ControlService @MSDN Function
exit () will terminate the process, which will certainly kill the process that hosts 1 service. However, it is undesirable to stop the service in a process that contains more than 1 service. Also, it is undefined whether other observers who control your service will receive a graceful notice of stopping the service if you use exit (). Other operating libraries in your process that you may have downloaded may also not work correctly if you use exit ().
exit, _exit @MSDN
source share