You could create a named event or mutex, and then switch it as the code executes. Then the external program can see this pulsation as an indication that the program is running.
I also used an internal watchdog system running on a different thread. This thread considers the main thread for activity, such as a log output or a switch event. If the activity is not visible, the service is considered to be hung, and I end the service. In this case, you can configure windows to automatically restart a stopped service, which can fix the problem (if this is not an internal logic error).
Also, the services I work with have text logs that are written to the log. In addition, for services that are going to "get some sleep," I am recording the time for the next wake up. I use MTAIL to view the log for output.
source share