1

I have a WCF service hosted in IIS. The service already has a class implementing IErrorHandler where I log exceptions thrown in the context of a service call. The problem is, when the service is called it spawns a new thread to perform additional processing. When testing I discovered that any exception thrown in this thread will not get caught by my error handler. So, what alternative do I have to log this exception? Is there any way to plug AppDomain.UnhandledException somewhere? I have no problem with the IIS process being killed, I just don't want the error to go unnoticed.

UPDATE:

For the moment, what I've done is plug the AppDomain.UnhandledException event in a shared constructor in the service class. It seems to work, but I'm not sure if it's the better way to do it.

Mike
  • 753
  • 1
  • 7
  • 16
  • does the launched thread job complete with in the context of main call ? or is it like a background job that keeps running even after response is sent ? – np-hard Nov 23 '11 at 03:07
  • @np-hard: It is a background thread. – Mike Nov 23 '11 at 14:24
  • 1
    i think your best option is to put error handing code in your background job, i had a similar [question](http://stackoverflow.com/questions/7896182/hosting-clr-and-catching-threading-exceptions) – np-hard Nov 23 '11 at 15:00

1 Answers1

1

I think you are at the mercy of the hosting environment for this situation. As @np-hard says you will need to handle the errors in your background job somehow.

You can be a little bit fancy about it - this is a good article about how to handle exceptions raised in background threads and move them into the foreground so they can be handled by the standard Application_Error handler. You could do that or just handle them directly and don't forward them on.

kmp
  • 10,535
  • 11
  • 75
  • 125