I've got two service processes (derived from System.ServiceProcess.ServiceBase
)
MyService1
and MyService2
.
I'm trying to run them both in the Main()
of a Windows Service's Programm.cs
.
static void Main()
{
ServiceBase[] servicesToRun = { new MyService1(), new MyService2() };
ServiceBase.Run(servicesToRun);
}
In the OnStart
methods of both MyService1
and MyService2
I write to a log file so I can tell they are running.
The system builds fine and I can install the service.
But only MyService1
runs. MyService2
doesn't do a thing (i.e. no start-up log entry). When I change the order in the array:
ServiceBase[] servicesToRun = { new MyService2(), new MyService1() }
only MyService2
runs.
To try to get to the bottom of this, I'm using a little tool AndersonImes.ServiceProcess.ServicesLoader (https://windowsservicehelper.codeplex.com/) to get around the limitation that you cannot directly debug a windows service in Visual Studio. With this tool I can get both services MyService1
and MyService2
to start and run next to each other. But I still don't know why Windows is running only the first item in the ServiceBase[] servicesToRun
array.
Any ideas?