Still creating windows services in .NET by hand?

Seriously stop and use Topshelf, why?…

  • Turns a console application into a windows service which allows much easier debugging
  • Uses a fluent interface to setup your services allowing easy in code setup
  • An instance can be provided at install allowing multiple same services on the same machine (which means you won’t need to read this)

The project site has a good Getting Started guide, once your ready to install the service, simply run this in a cmd prompt in the same directory as your exe:

myservice.exe install /instance:test

2 thoughts on “Still creating windows services in .NET by hand?

  1. From the doco: “You can only have ONE service! As of 3.x Topshelf the base product no longer support hosting multiple services. This was done because the code to implement was very brittle and hard to debug. We have opted for a simpler and cleaner base product. This feature will most likely come back in the form of an add on nuget.”
    I guess I’m back to your other article…

  2. Or you could treat the service that gets registered with Topshelf as a coordinator that has a reference to the other services that need to be ran/paused/stopped and when the coordinator is actioned upon it then forwards the method call onto the others, basic example:

    public class ServiceCoordinator
    protected Service1 service1;
    protected Service2 service2;

    public ServiceCoordinator(Service1 service1, Service2 service2)
    this.service1 = service1;
    this.service2 = service2;

    public void Start()

    public void Stop()

    cfg.Service<ServiceCoordinator>(setup =>
    setup.ConstructUsing(name=> DependencyResolver.Resolve<ServiceCoordinator>());
    setup.WhenStarted(svc => svc.Start());
    setup.WhenStopped(svc => svc.Stop());

Comments are closed.