Impact of Exit Function in Windows Service Programs

I have a program that is a windows service. It is started by the StartServiceCtrlDispatcher function. This is a network server that accepts user inputs as a command for control purposes. Now I want him to be able to disconnect from users, i.e. When the user enters the "exit" command, the service will stop. (Don't worry about how you can start the service again.) Can I just use the exit function in the standard library, or do I need to use the ControlService function?

+1
source share
1 answer

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

+2
source

Source: https://habr.com/ru/post/1445301/


All Articles