Click here to Skip to main content
13,046,464 members (72,734 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


10 bookmarked
Posted 15 Apr 2011

Multiple File Watcher Services in One Windows Service Project C#

, 15 Apr 2011
Rate this:
Please Sign up or sign in to vote.

Note: There is a Document sub folder and an InstallerBatch sub folder included in the entire solution containing some good information/comments and the installation/uninstallation batch files.

What I am Trying to Achieve

I'm trying to put multiple services into one service, with one same name. So, When you do "net start TheService", it will start Service1() and MySecondUserService().

What I Have Done

I thought adding another service to my project and changing the services to run would be sufficient.
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};

When I install and run this,
only the first service is run "Service1".

The solutions is not to add another project installer, but a service installer, which is a component on the project installer. That newly added service installer has to have second service name configured.



Like code below:


Must have 2 serviceInstaller’s and 1 serviceProcessInstaller

In Installer1.Designer.cs code must be like below:

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
    this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
    this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
    this.serviceInstaller3 = new System.ServiceProcess.ServiceInstaller();
    // serviceProcessInstaller1
    this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
    this.serviceProcessInstaller1.Password = null;
    this.serviceProcessInstaller1.Username = null;
    // serviceInstaller1
    this.serviceInstaller1.Description = "TEST WATCHER1";
    this.serviceInstaller1.DisplayName = "Test Watcher1";
    this.serviceInstaller1.ServiceName = "Test Watcher Service #1";
    // serviceInstaller3
    this.serviceInstaller3.Description = "TEST WATCHER3";
    this.serviceInstaller3.DisplayName = "Test Watcher3";
    this.serviceInstaller3.ServiceName = "Test Watcher Service #3";
    // Installer1
    this.Installers.AddRange(new System.Configuration.Install.Installer[] {



private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
private System.ServiceProcess.ServiceInstaller serviceInstaller1;
private System.ServiceProcess.ServiceInstaller serviceInstaller3;

In both Service1.Designer.cs and Service3.Designer.cs files, below must be true:

this.ServiceName MUST match this.serviceInstaller1.ServiceName in Installer1.Designer.cs file
this.ServiceName MUST match this.serviceInstaller3.ServiceName in Installer1.Designer.cs file


  • Putting multiple services in one single Windows Service
    .exe file can allow one step installation. One installation will have all the
    services installed in the Service Controller and all can be viewed in the
    Services MMC snap-in.

  • Also may be multiple services can share code.


The only issue found so far is that after all the services started, if one or more (but not all) stopped, the "stopped" service(s) is/are still running somehow at the background. To avoid this type of behavior, all other services that still need to run will have to do a restart in order to have all the stopped services truly stop.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 15 Apr 2011
Article Copyright 2011 by qizhigang
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid