views:

661

answers:

1

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?

+1  A: 

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.

Tom Anderson
i would like to do this but we use the windows service controller to run scripts and report on when the services die. because of this i would like to let the errors occur "naturally". thanks tho
marshall
I guess then I am a bit confused, without error handling, if one of the services bomb, the entire assembly will bomb.
Tom Anderson
I'll rate you for the comment then. If it's not possible to avoid the assembly dying if there is an exception then I guess I'll just have to create truly separate services. Thanks
marshall