Re: C# service, performs lots of things on start, windows doesnt give it enough time!



On Aug 28, 10:06 am, UL-Tomten <tom...@xxxxxxxxx> wrote:
On Aug 27, 11:37 pm, "t...@xxxxxxxx" <craig.whitco...@xxxxxxxxx>
wrote:

ThreadStart starter = new ThreadStart(DoSomething);
Thread t = new Thread(starter);
Service now starts immediately. I have the feeling though that this is
cheating and not fixing an underlying problem.

Maybe, maybe not. You could try looking at it from the point of view
of whoever is consuming the service. Is it important for the consumer
to know whether the service has finished the set-up work it does when
it starts? (For example, if the Windows Firewall Service is listed as
"Started", consumers would probably think it's safe to connect to the
Internet. Let's say the Firewall Service does what you do above, and
doesn't start censoring the Internet until DoSomething() is finished.
In this case, your approach is definitely cheating. But if requests to
and from the Internet will be pending in some sort of queue while the
Firewall service is DoingSomething, then it's still safe (but
certainly clumsy).)

As others have stated, a common compromise is to do only in OnStart()
what you need to tell the SCM whether you can actually start at all.
(For example, if the service really requires an Internet connection to
operate, then you might not want to tell the SCM you have started if
you cannot detect the presence of a suchly connection.)

sorry guys, I was unclear. I am not concerned with the amount of time
my code takes to execute. I am not trying to speed that up.

I am trying to improve the speed of which the SCM shows the service as
"started" not "starting", because sometimes, the download of the RSS
items takes so long that the SCM gives up thinking the service has
hung.

Moving the code from onstart has fixed it, but I want to learn how I
can acheive the same thing better (ie, is there a way to tell SCM that
the service has started successfully etc etc)

Craig

.



Relevant Pages