C# Windows Service - Issue Creating Multiple Services in 1 Project
-
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!
-
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!
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:
-
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:
-
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!
Thanks for the update! :) Cheers, Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: