How to capture unhandled exceptions on Windows Services?

Jader Dias picture Jader Dias · Feb 25, 2011 · Viewed 7.7k times · Source

I use AppDomain.UnhandledException Event to capture unhandled exceptions on WPF, Console and WinForms apps.

But the same code isn't working on Windows Services. What should I do?

Answer

Chris Dickson picture Chris Dickson · Feb 25, 2011

See my answer added to the linked SO question.

There are a number of places in your service code where a thrown exception will not be "unhandled" even if you don't handle it, because the base class does so before it reaches the AppDomain's default handler.