I have an application that manages heavy processing for my project and need to convert it to Windows Service. I need to allow multiple instances of application processing versions to run, which seems to be a pretty normal requirement.
I can see at least three approaches for this:
- Create one installed directory (EXE, DLL, config), but install it as multiple service instances.
- If a single instance of services starts several instances of itself after starting, a la Apache.
- Ask a single service instance to invoke multiple threads running in the same process space.
My intention was approach number 1, but I continued to overcome the limitations, both in design and in documents for services:
- Are OnStart () parameters passed by standard service mechanisms on the system unattended? If so, when / why?
- Passing runtime parameters through the ImageKey registry seems kludge, is there a more efficient mechanism?
- I got an application to install / uninstall myself as a pair of services ("XYZ # 1", "XYZ # 2", ...), using ImageKey to pass it an instance number of the command line parameter ("- x 1", "-x 2 "), but I missed something. When you try to start a service, it will fail: "The executable program for which this service is configured to start does not run the service.
So the questions are:
- Is there a brief description of what happens when the service starts, especially for situations where the ServiceName is not hardcoded (see above).
- Has anyone used approach number 1 successfully? Any comments?
NOTE. I posed the problem using approach number 3, so I can not justify a lot of time to understand this. But I thought that someone might have information on how to implement No. 1, or about good reasons why this is not a good idea.
[Edit] I initially had the 4th option (install multiple copies of the application on the hard drive), but I deleted it because it just feels, um, a hacker. That is why I said "at least three approaches."
However, if the application is not recompiled, it must dynamically set its ServiceName, therefore, it has a solution to the third problem / problem above. Thus, if an instance does not need to modify its installation files, # 1 should work fine with the N configuration files in the directory and in the registry entry indicating which instance should use.
c # windows-services
NVRAM
source share