mjallday
mjallday

Reputation: 10102

Multiple Windows Services, One Installer, Removing Dependencies

I have a single service installer project that installs multiple services. This is great but a single unhandled exception in any single service will stop all services that were installed by this installer.

The code for the installer looks something like this

ServiceBase[] ServicesToRun;

ServicesToRun = new ServiceBase[] 
{ 
    new Service1() ,
    new Service2() ,
    ...
};

ServiceBase.Run(ServicesToRun);

So once the service is installed I can see several separate services in the windows service management window and each can be started, stopped, paused, resumed independently.

However if one suffers an unhandled exception then they all stop.

Ideally only the service that had the problem would stop and the other services would continue on their merry way.

Can anyone suggest a way to do this without creating a truly separate installer project for each service?

Upvotes: 1

Views: 2426

Answers (1)

Tom Anderson
Tom Anderson

Reputation: 10827

Add independent error handling per service at the highest level, this way not all of the services will be effected.

You may also want to add a auto service restart if the error is not critical. Just be sure you add tons of logging in the case of service shut downs and restarts from errors.

Upvotes: 1

Related Questions