private static void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
{
if ((Thread.CurrentThread.ThreadState & (ThreadState.AbortRequested | ThreadState.Aborted)) != 0)
{
return;
}
if (ShouldSuppressFirstChanceLogMessages)
return;
using (SuppressFirstChanceExceptionLogMessages())
{
try
{
var perm = new ReflectionPermission(PermissionState.Unrestricted);
perm.Demand();
}
catch (SecurityException)
{
//Cannot raise messages if this permission is denied.
return;
}
try
{
EventFirstChanceException.Publish(null, null, e.Exception);
}
catch (Exception)
{
//swallow any exceptions.
}
ThreadLocalThreadStack.Value.PreviousFirstChanceExceptionSequenceNumber++;
}
}