tags:

views:

52

answers:

1

I have a program that is a windows service. It is started by StartServiceCtrlDispatcher function. It's network server that accepts user's inputs as command for controlling purposes. Now, I want it to have the ability to be shutdown by users, i.e. when user type a "quit" command, the service will stop. (Don't worry about how the service can be started again.) Can I just use "exit" function in standard library or do I need to use "ControlService" function?

+2  A: 

You should use the ControlService() function to stop the service, and then return from program flow normally if this should also cause the process to exit.

ControlService Function @ MSDN

exit() will cause process termination, which will definitely kill a process that hosts 1 service. However, this is undesirable for stopping a service in a process that hosts more than 1 service. Also, it is undefined whether other observers monitoring your service will receive graceful notification of the service stop if you use exit(). Other operating libraries in your process that you may have loaded, may also fail to stop correctly if you use exit().

exit, _exit @ MSDN

meklarian