We are trying to implement a single Windows Services that starts multiple services under the same process. According to code I've seen you do the following:
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1(),
new Service2()
};
ServiceBase.Run(ServicesToRun);
}
However, this code only executes Service1 and not Service2. Both Service1 and Service2 execute by themselves. Any ideas?
Best Answer
I would think you would want to create a sub service model where one could start any number of sub services from the main windows service.
Then maybe a base Threaded Service class..
Configure your services through the app.config and an IConfigurationSectionHandler...
Something to handle the config sections...
then you simply create however many threadedservice based classes you need for your sub services, and throw them all into the app.config...something like..
and lastly, in your actual service code, just have to do ServiceConfiguration.Current.Start( ) on the start, and Service.Configuration.Current.Stop( ) in the exit.
Hope that helps!