469,584 Members | 2,255 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,584 developers. It's quick & easy.

Windows service. "Running" my class

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();
}
Nov 17 '05 #1
3 1463
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

"Claire" <no***@yournelly.com> wrote in message
news:ui**************@TK2MSFTNGP10.phx.gbl...
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();
}

Nov 17 '05 #2
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" wrote:
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();
}

Nov 17 '05 #3

"Claire" <no***@yournelly.com> wrote in message
news:ui**************@TK2MSFTNGP10.phx.gbl...
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.

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by John Spiegel | last post: by
2 posts views Thread by H Branyan | last post: by
4 posts views Thread by tshad | last post: by
4 posts views Thread by Mr BigSmoke | last post: by
5 posts views Thread by =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.