Windows service. "Running" my class

  • Thread starter Thread starter Claire
  • Start date Start date
C

Claire

Sorry for such a daft question.
Ive been following some tutorials on creating windows services. Ive not done
them before.
In my original debuggable windows form application, I create my worker
classes. The classes 'run' themselves using several threads and only stop
when the form is closed.
Now I've used these worker classes in the service application. When I try to
run my service manually, I am given a message that the service stopped
itself. I'm not sure if there's a problem with my code yet, but it led me
to wonder if the following code would just lead to my object being created
followed immediately by the function exiting and the service finishing. Is
there anything I need to do to keep driving a service application?

private MMonitor Monitor = null;

protected override void OnStart(string[] args)
{
Monitor = new MMonitor();
}
 
Hi Claire,

From the debugger stand point I think that it will treat your service
application like any other application. When you register the application
as a service it stays memory resident until it receives a service stop event
from the SCM. When in debugger mode there is no SCM to issue the events so
treat it like any other applicaiton. Now speaking for MMonitor, is this a
threaded class that you created, for debugging purposes if you could
implement a "wait" signal so that you can do something like:

Monitor.WaitFor();

Then your main service thread will idle until the Monitor object is
completed with its task and stay memory resident (not terminated).

Alex
 
Hi Claire,

In order to test what is going on add your initialization code on the
OnContinue, so run the service and the pause it, attach your debugger and the
put a breakpoint on OnContinue, Press resume and you can see what is going on.

hope this helps to solve it
salva
 
Claire said:
Sorry for such a daft question.
Ive been following some tutorials on creating windows services. Ive not
done them before.
In my original debuggable windows form application, I create my worker
classes. The classes 'run' themselves using several threads and only stop
when the form is closed.
Now I've used these worker classes in the service application. When I try
to run my service manually, I am given a message that the service stopped
itself. I'm not sure if there's a problem with my code yet, but it led me
to wonder if the following code would just lead to my object being created
followed immediately by the function exiting and the service finishing. Is
there anything I need to do to keep driving a service application?

private MMonitor Monitor = null;

protected override void OnStart(string[] args)
{
Monitor = new MMonitor();
}

OnStart is meant to initialize you service and to start your service task on
another thread. Your service will be flagged as "failed to start in a timely
fashion" if you don't return within 30 seconds after the service start
command.
I'm unclear on what you are doing in your MMonitor constructor, but it looks
like you simply return, as a consequence you return from OnStart without
having created a service thread.

Willy.
 
Back
Top