c# - Multiple Windows Services in One exe -


I'm trying to create many Windows services to do many different things. For example, I need Windows services:

  1. Send a daily report via email
  2. From time to time, some archived information every 30 minutes
  3. Clear etc.

I have different functions to meet the needs of windows so I really do not like the idea of ​​placing it in one service.

What I have so far is a project in Visual Studio 2008. I have created a Windows service, I have set a timer on the online event (it just writes in Test file every 5 seconds for testing purposes). I then added an installer to the project and when I run InstallUtil.exe, everything works fine.

The problem occurs when I add a second window service for the same project. With the service of the other windows, I have installed an onstart code again with the same logging information (slightly different so I can tell which service is typing in the log), I have the main event from Program.cs Changed from:

  Fixed zero main (string [] args) {ServiceBase [] ServicesToRun = new servicebase [] {new service1 ()}; ServiceBase.Run (ServicesToRun); } { 

From:

  Fixed zero main (string [] args) {ServiceBase [] servicesToron = new servicebase [] {new service 1 (), New service 2 ()}; ServiceBase.Run (ServicesToRun); }  

At this point, there are no compile time errors, but Service 2 does not do anything ... the logging task never fire.

The fact that I compressed it down is the fact that the "installer" does not have it attached to the other service, then I tried to add an installer with the first service (i.e., right click on service designer And click "Add Installer"). Now, when I go to the ProjectInstaller.cs file, there is another service installer (Service Installer 2).

Now when I create a project and try to install services, and I try to start the Service "Control Panel" window, and I start Service1, I get the following error message :

The Service 1 service on Windows local computer could not start.

Error 1083: Executable program that is configured to run this service does not implement the service.

I get the same error message while trying to start Service 2 (with the exception that the error message is identified

< Item class = "post-text"

Itemprop = "text">

I have come to know how an executable but two services to each service service manager Your name is installed with the ability to install / stop. I think this is what you want, right? Here I am

  • A service project was created.
  • Added a second service (with a unique service name) in the same project
  • both An installer was added to the Services (ServiceA and Service B)
  • In the ProjectInstaller.Designer.vb file, I changed the Me.Installers.AddRange line to show both service installer. (My Service Instalar 1 , M. Service Installer 2)
  • In the main entry point of the main service (Service A in my case), I The service was set in the servicebase in the servicebase, which included all the services I want to run (Service A and Service B) This is an important step because the service manager here determines a property based on the number of arguments - To allow multiple instances of the same example or just an example
  • Add an installer project and use the services of the services I
  • Add Custom Action Using Output from Services
  • You can find demo codes here:

    enjoy!


    Comments

    Popular posts from this blog

    python - Overriding the save method in Django ModelForm -

    html - CSS autoheight, but fit content to height of div -

    qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -