Hello Phil, thanks for your answer. So, you suggest that I only shoul
initialize variables in OnStart method? And how do I start the threads
then? Could you provide some code example of the model you talk about?
Another question is: If i do my service dependant on other, windows
will launch first the necesary services before launching mine?
It is the first windows service i write and in the examples i saw in
internet people usually start the threads in OnStart event. I'm also
overwriting the OnStop event handler, an there I stop the threads I
launched. As they are not cooperating in any way, it's not important
the order. Any help would be apreciated. Thanks again.
Oscar Acosta
If you set up the dependencies correctly then yes, your service will start
after the event log service has started.
There are always lots of ways to do something, but this is the general model
for services that I prefer:
http://www.codeproject.com/csharp/cron.asp
where a thread belonging to the class is started in OnStart and stopped in
OnStop, and the thread runs some method you implement. However it's cleaner
to use a ManualResetEvent that the thread checks periodically so that it can
shut down cleanly, rather than Thread.Abort used there. Your ThreadPool
doesn't seem to deal with the case where the service gets stopped (how do
you shut down the threads etc). So you might get into some issues when you
try to stop your service unless you deal with that. However I suspect your
crashing problem at boot time is your dependency on the event log service.

Signature
Phil Wilson [MVP Windows Installer]
----
> Hello Phil, thanks for your answer. So, you suggest that I only shoul
> initialize variables in OnStart method? And how do I start the threads
[quoted text clipped - 62 lines]
>> > JobWs and JobManteinance are two functions that do all the work.
>> > Thanks in advance.
oscar.acostamontesde@googlemail.com - 20 Jul 2006 12:59 GMT
Hello Phil. Thanks a lot, you were completely rigth about it, I added
the dependency and the service now starts fine!
I was using the ThreadPool because I was getting mad about the reason
for the service not starting. So I thougt
that maybe the overhead caused by the new threads were the problem, and
I decided to use the threadpool thinking that maybe as those threads
were already created by the framework i could win some miliseconds ;)
Thanks a lot again!
Oscar Acosta
> If you set up the dependencies correctly then yes, your service will start
> after the event log service has started.
[quoted text clipped - 80 lines]
> >> > JobWs and JobManteinance are two functions that do all the work.
> >> > Thanks in advance.
oscar.acostamontesde@googlemail.com - 21 Jul 2006 11:15 GMT
Hello again. I have one more question. Is there any way to know all the
services that mine depends on?
Thanks,
Oscar Acosta
> If you set up the dependencies correctly then yes, your service will start
> after the event log service has started.
[quoted text clipped - 80 lines]
> >> > JobWs and JobManteinance are two functions that do all the work.
> >> > Thanks in advance.