I have some questions about Windows Services. I have done a lot of searching but cannot seem to find the answers so I am hoping someone here can help. I have written an app that runs fine as a daemon in Linux, but want to implement it as a Service in Windows. The program needs to run continually in the background. That part works fine in Linux. The problem comes when I try to create this as a Windows Service.
In the Linux daemon version, it runs in a while loop until a boolean flag is changed. Unless it is signaled to exit (I am using signal handlers to manage this for Linux), the flag doesn’t get set to cause it to exit, therefore creating an otherwise endless loop. I am also using the “Call Daemonize” statement with compiler directives if the executable is for Linux. For Windows, I go into the same loop but do not call daemonize. Is that correct?
I looked at the Empty Service template and it appears that the only thing I would need to do to my existing console app to make it a service is change the App.Super to “Service Application” as well as define code for the other App Event Handlers such as Resume, Paused, Stopped, Run, etc. Is that correct? Unfortunately, that doesn’t seem to work for me. As a console app, the daemon runs in the “endless” loop, but when I change its super to Service Application and re-compile, the program exits immediately.
What should be the behavior of a Windows Service executable? If it is run from the command line should it loop or return immediately?
I want this to eventually be a part of a setup program (using Inno Setup). Would it be better to have command line arguments “install” and “uninstall” which use a Real Basic library to setup the service in Windows and remove it if uninstall is called? Or would it be better to use a library within Inno Setup? This is more of a best practice type of question assuming I get the service to work at all.
Again, I appreciate any help with the questions. I am just new to developing Windows Services and am having difficulty finding answers to these questions and my typical trial-and-error approach of experimentation doesn’t seem to be providing the answers I need.