I\'m using the FirstChanceException event to log details about any thrown exceptions.
static void Main(string[] args)
{
AppDomain.CurrentDomain.FirstChanceEx
First use a method instead of a delegate, so the method name will be defined
Then use Environment.StackTrace to check if the method is already in the stacktrace
Here is a piece of code untested:
static void Main(string[] args)
{
AppDomain.CurrentDomain.FirstChanceException += handleFirstChanceException;
}
private void handleFirstChanceException(object sender, EventArgs eventArgs)
{
if (Environment.StackTrace.Contains("handleFirstChanceException"))
return;
// handle
}
I think the above will not work because it'll always contains the method name, but you can count if it appear more than 1 time. Also, check that it's not inlined when you compile in Release mode, in this case you're in trouble