Windows service thread seems dead

  • Thread starter Thread starter Jason Barnett
  • Start date Start date
J

Jason Barnett

I created a Windows service with a worker thread which performs some work
every 5 minutes; sleeping in between. Everytime it performs the work, it
writes a status to a log file. The service runs fine most of the time, but
sometimes it seems to do nothing; the status in Services Manager is
"Started", but the log file is no longer updated with a status.

All errors are written to the log file and to the Event Log using a
try...catch block at the main entry point (main method) and using a
UnhandledExceptionEventHandler (initialized upon entering the main method.
However, no errors appear in the log file when the status stops getting
written.

I suspect that the thread is ending abnormally, but the main process is not.
I'm not sure what step to take next to ensure this service runs more
reliably. Could someone offer some suggestions?
 
Jason Barnett said:
I created a Windows service with a worker thread which performs some work
every 5 minutes; sleeping in between. Everytime it performs the work, it
writes a status to a log file. The service runs fine most of the time,
but
sometimes it seems to do nothing; the status in Services Manager is
"Started", but the log file is no longer updated with a status.

All errors are written to the log file and to the Event Log using a
try...catch block at the main entry point (main method) and using a
UnhandledExceptionEventHandler (initialized upon entering the main method.
However, no errors appear in the log file when the status stops getting
written.

I suspect that the thread is ending abnormally, but the main process is
not.
I'm not sure what step to take next to ensure this service runs more
reliably. Could someone offer some suggestions?

The only thing you can really do is a function on a timer on the main thread
to check the status of a child thread to be alive and report if the child
thread is not alive, which means you'll have to stop the service and restart
it manually to get the child thread active again.


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4534 (20091022) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
I suspect that the thread is ending abnormally, but the main process is not.
I'm not sure what step to take next to ensure this service runs more
reliably. Could someone offer some suggestions?

Why not try running a debugging tool against the service when you
suspect it's hung. e.g.
http://www.microsoft.com/downloads/...F7-D710-47E3-8B95-5A6555A230C2&displaylang=en

Put some copious logging into your worker thread so you know what it was
doing when it stopped. If the problem is repeatable and you find it
always stops at the same place it should make things a lot easier to
fix. I have to do this occasionally as developers aren't allowed any
access to live hosts where I work, so debugging difficult to reproduce
problems at arms length becomes second nature. Usually the fix only
takes 5% of the time it takes to find the problem.

Good luck!
 
I created a Windows service with a worker thread which performs some work
every 5 minutes; sleeping in between.  Everytime it performs the work, it
writes a status to a log file.  The service runs fine most of the time,but
sometimes it seems to do nothing; the status in Services Manager is
"Started", but the log file is no longer updated with a status.

All errors are written to the log file and to the Event Log using a
try...catch block at the main entry point (main method) and using a
UnhandledExceptionEventHandler (initialized upon entering the main method..  
However, no errors appear in the log file when the status stops getting
written.

I suspect that the thread is ending abnormally, but the main process is not.
 I'm not sure what step to take next to ensure this service runs more
reliably.  Could someone offer some suggestions?

I had a similar problem that was caused by file locking on the
computer. In my case I was continually getting XML files which I
processed every 5 minutes. During this waiting period I renamed the
files and only processed the latest file. However the system would
place a lock on the file and if the timing was just right, which
happened more that I would have thought, the system would just stop
responding. I fixed it by putting the copy in a try catch, sleeping 5
seconds and trying again. I know it's not elegant but I haven't had a
problem in the last 5 months. Thought I'd pass it along in case you
are doing something similar.
 
I already added logging into my worker thread, at it's entry point. However,
I revisited the code there and found a potential problem with the code. I
found that the thread could complete without error, even though it should
continue looping.
 
Back
Top