mike said:
I'm still not sure how to do this.
Mike -
With the .NET Framework you implement method overrides in your class
which are inherited from the ServiceBase class of the framework. The
..NET wizard created this class for you.
OnStart and OnStop are about a minimum for you to override/implement.
The service control manager (SCM or "scum") loads your service EXE and
invokes your OnStart (basically). Then in response to a request to stop
the service it will invoke your OnStop override. When you return from
THIS call, your service executable exits, and the process goes away.
The work of your service is NOT performed in OnStart. You must get your
service started up and running in OnStart, and then return to caller as
soon as you can. Typically one would create a thread which is sometimes
a loop which performs your service activity. Or perhaps you may start a
timer. Or use some other system component which has a callback for you
to respond to.
When responding to OnStop you undo what you started in your OnStart. You
cause your service thread to exit. You exit the loop. Stop the timer. Or
dispose the other system component which is making call backs for you.
In any case, be sure everything is shutdown cleanly before you exit the
OnStop override in your implementation. But when you exit the OnStop
method, the executable exits and your process is gone. Consider what
your service is "waiting for" or "watching to happen" in its primary
function. Often times the mechanism needs to addtionally use a
ManualResetEvent, or something similar, so your main "wait for
something" can way for the MRE as well. Then in OnStop set the MRE to
trigger the service thread to exit. Typically you need a little extra
infrastructure to support stopping the primary activity in this way.
HTH
- Lee