Windows Service crashing upon starting

  • Thread starter Thread starter Razzie
  • Start date Start date
R

Razzie

Hey all,

I wrote a Windows Service. When I test it on my developement machine (winXP)
it works fine. It starts ok, never crashes, etc.
When I install the service on another machine (win2000) it *sometimes*
crashes upon starting. The progressbar you get when you manually start the
server will very slowly progress, and when it hits 100% after 2 minutes or
something I get the error 'The service could not be started because it did
not respond in a timely manner' or something like that. No eventvwr error
codes, nothing. The status of the service keeps saying 'starting' and the
funniest thing is, sometimes it actually WILL run in the background (I can
check that because of log files etc). However, I can't stop the service
after that, because the stop / start buttons are grayed out, I can't
terminate the process from the task manager (access denied). And when it
does NOT crash, it keeps running flawlessly until the machine is rebooted,
or I manually terminate it.
So two questions:

- Why does it *sometimes* crash on the win2000 server? It doesn't do any
fancy stuff, just connect to a database, copy some data, etc.
- IF it crashes, is there any way to terminate the service when it stopped
responding? Having to reboot the machine is a pain, especially when the
server uptime is an important thing.

Thank you!

Razzie
 
Hi,

You should always create a new thread in the OnStart() method and let this
method to end , also you should use the EventLog to log any error you get at
the service, believe me it helps a LOT.

probably you are accesing the DB before ends OnStart() hence your
OnStart() takes longer that it should and you get the error.

Do this, on the OnStart() method just create the thread and the event
logger and do all the work on another thread.


cheers,
 
I will give it a try. Thanks!

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

You should always create a new thread in the OnStart() method and let this
method to end , also you should use the EventLog to log any error you get
at
the service, believe me it helps a LOT.

probably you are accesing the DB before ends OnStart() hence your
OnStart() takes longer that it should and you get the error.

Do this, on the OnStart() method just create the thread and the event
logger and do all the work on another thread.


cheers,
 
Back
Top