How to resolve an exception in windows service( .net framework 2.0)

  • Thread starter Thread starter zh.zhen
  • Start date Start date
Z

zh.zhen

i use try..catch in my windows service,and when some exception occurs,
i write it to event logs.
in webapplication ,if you use a catch to "hold" an exception, and do
not throw up, the exception will be ignore if it is available.

my windows service is a mul-thread service, which workes for a growing
work-list. but some workitems of this list will make erros when
services is running for it.

the question is:
when exception occurs, the service is terminated. how can i let the
service continue running without any termination?
 
i use try..catch in my windows service,and when some exception occurs,
i write it to event logs.
in webapplication ,if you use a catch to "hold" an exception, and do
not throw up, the exception will be ignore if it is available.

my windows service is a mul-thread service, which workes for a growing
work-list. but some workitems of this list will make erros when
services is running for it.

the question is:
when exception occurs, the service is terminated. how can i let the
service continue running without any termination?

You could try a set the Exception to Null. I have done that when an
Exception has occlude in a try/catch to clear the Exception so that it
wouldn't bubble up causing another method that called it to terminate above
it.
 
In .NET 2.0 an unhandled exception on any thread will bring down the whole
appdomain and therefore your managed executable. the solution would be to
handle the exception before it bubbles to the top of the call stack and then
let the thread terminate gracefully. there is no special case with Windows
Services, if you handle an exception, it will not propagate (except in the
casse of ThreadAbortException)

A question worth asking is if you are really benefitting from running a
growing list of tasks concurrently? If so, have you considered using the
ThreadPool to mitigate some of the issues of running unbounded numbers of
threads?
 
Back
Top