Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Windows Service - Issue Creating Multiple Services in 1 Project

C# Windows Service - Issue Creating Multiple Services in 1 Project

Scheduled Pinned Locked Moved C#
helpcsharpdockertutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brett G 0
    wrote on last edited by
    #1

    Hello all: I am having a problem with a Windows Service that I'm writing in C# using Studio 2003. The main service will start fine, but for some reason the OnStart() and OnStop() methods in the additional service never fire on their own. As a workaround, in the second service I added a line to the InitializeComponent() method to call OnStart() since the Initialize method is actually called. This works as a workaround to get the service doing what it should, but then the OnStop() is never used and this seems a little odd to me. It does work this way, but I can't believe this is how it should be and I would like to have it running right. If you have any ideas, any help would be appreciated. Main Method in first service:

    // The main entry point for the process
    static void Main()
    {
    System.ServiceProcess.ServiceBase[] ServicesToRun;

    // More than one user Service may run within the same process. To add
    // another service to this process, change the following line to
    // create a second service object. For example,
    //
    //   ServicesToRun = new System.ServiceProcess.ServiceBase\[\] {new Service1(), new MySecondUserService()};
    //
    
    ServicesToRun = new System.ServiceProcess.ServiceBase\[\] { new MendsInterface(), new       MendsToAllscripts()};
    
    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
    }
    

    Initialize Method in the second service:

    private void InitializeComponent()
    {
    components = new System.ComponentModel.Container();
    this.ServiceName = "MendsToAllscripts";

    \_common.LogMessage("Initializing Allscript service");
    
    OnStart(null);
    

    }

    Thank you!

    M 1 Reply Last reply
    0
    • B Brett G 0

      Hello all: I am having a problem with a Windows Service that I'm writing in C# using Studio 2003. The main service will start fine, but for some reason the OnStart() and OnStop() methods in the additional service never fire on their own. As a workaround, in the second service I added a line to the InitializeComponent() method to call OnStart() since the Initialize method is actually called. This works as a workaround to get the service doing what it should, but then the OnStop() is never used and this seems a little odd to me. It does work this way, but I can't believe this is how it should be and I would like to have it running right. If you have any ideas, any help would be appreciated. Main Method in first service:

      // The main entry point for the process
      static void Main()
      {
      System.ServiceProcess.ServiceBase[] ServicesToRun;

      // More than one user Service may run within the same process. To add
      // another service to this process, change the following line to
      // create a second service object. For example,
      //
      //   ServicesToRun = new System.ServiceProcess.ServiceBase\[\] {new Service1(), new MySecondUserService()};
      //
      
      ServicesToRun = new System.ServiceProcess.ServiceBase\[\] { new MendsInterface(), new       MendsToAllscripts()};
      
      System.ServiceProcess.ServiceBase.Run(ServicesToRun);
      }
      

      Initialize Method in the second service:

      private void InitializeComponent()
      {
      components = new System.ComponentModel.Container();
      this.ServiceName = "MendsToAllscripts";

      \_common.LogMessage("Initializing Allscript service");
      
      OnStart(null);
      

      }

      Thank you!

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Brett G wrote:

      I added a line to the InitializeComponent() method to call OnStart()

      That's no good. OnStart() is meant to be called in response to the service control manager.

      Brett G wrote:

      The main service will start fine, but for some reason the OnStart() and OnStop() methods in the additional service never fire on their own

      How are you starting the additional services? If you're not getting OnStart/OnStop calls then the service hasn't started.

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      B 1 Reply Last reply
      0
      • M Mark Salsbery

        Brett G wrote:

        I added a line to the InitializeComponent() method to call OnStart()

        That's no good. OnStart() is meant to be called in response to the service control manager.

        Brett G wrote:

        The main service will start fine, but for some reason the OnStart() and OnStop() methods in the additional service never fire on their own

        How are you starting the additional services? If you're not getting OnStart/OnStop calls then the service hasn't started.

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        B Offline
        B Offline
        Brett G 0
        wrote on last edited by
        #3

        Just realized that I only had one service installer set up. Added a second installer for the other service and things are running much better now. Thanks!

        M 1 Reply Last reply
        0
        • B Brett G 0

          Just realized that I only had one service installer set up. Added a second installer for the other service and things are running much better now. Thanks!

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Thanks for the update! :) Cheers, Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups