1

I have a windows service that does one particular job. Now if there were two or more instances (hypothetically speaking) each instance would differ in configuration only, but they would do the same job basically. They'd only be referring to different databases, tables as per configuration.

But I am looking for an approach on how I can increase/decrease the instances of such services? Looking for a small architecture for managing this...

PS: It is very simple to do this in windows azure; the difference being you'd increase/decrease the number of VM instances, and you can configure in database what each VM instance should do.

deostroll
  • 11,661
  • 21
  • 90
  • 161

1 Answers1

2

I think the problem you're facing is that multiple instances of services can't share the same name. The way I work around this is install the instances under different names. You can have your service installer class absorb a parameter:

[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
    public ProjectInstaller()
    {
        InitializeComponent();
    }
    public override void Install(IDictionary stateSaver)
    {
        ResolveServiceName();
        base.Install(stateSaver);
    }

    private void ResolveServiceName()
    {
        serviceInstaller1.ServiceName = Context.Parameters["ServiceName"];
        serviceInstaller1.DisplayName = Context.Parameters["ServiceName"];
    }
    public override void Uninstall(IDictionary savedState)
    {
        ResolveServiceName();
        base.Uninstall(savedState);
    }
}

And when you're installing the service, you provide the ServiceName parameter:

installutil.exe /ServiceName=foo YourService.exe
theiterator
  • 335
  • 5
  • 12