Given that:
- taking a lock while in a finalizer can cause deadlocks
- finalizers can throw exceptions
Is it safe to take a lock while inside an unhandled exception handler or can the code below cause deadlocks?
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
//do other stuff
}
private static object loggingLock = new object();
static void CurrentDomain_UnhandledException(
object sender,
UnhandledExceptionEventArgs e)
{
lock (loggingLock)
{
//log the exception
}
}