I have two windows services that I've written: the first is a "Listener
Service" that listens for MSMQ Message delivery. The second is a
"Watcher Service" that monitors the state of the first. If the
"Listener Service" goes down I want the "Watcher Service" to receive a
notification and perform a set action.
To enable this communication I've written a separate assembly (that
both services reference) that exposes two interfaces :
IServiceStatePublisher and IServiceStateSubscriber. The way that I
register the "Watcher Service" as a subscriber to the "Listener
Service" is with the following code in the OnStart event of the
"Watcher Service"::
protected override void OnStart(string[] args)
{
//Line 1
ServiceBase qw = new QueueWatcher();
//Line 2
((IServiceStatePublisher)fd).addSubscriber((IServi ceStateSubscriber)this);
//Line 3
ServiceBase.Run(qw);
}
I thought it reasonable that this would work, however, when I start the
"Watcher Service" the Application Event log shows the message "Service
cannot be started. An instance of the service is already running". I've
determined that the error is specific to the code at Line 3, but I
can't identify the reason it's happening. Neither service is running
when the "Watcher Service" is started and I don't have the ability to
step into the ServiceBase code to see what's going on there.
I'm stumped, so any help is greatly appreciated.