An exception due to the use of Application.ThreadException and AppDomain.CurrentDomain.UnhandledException

I had a problem with the application freezing and setting the default message “Please inform Microsoft about this problem” instead of the “unhandled exception” dialog box in the application.

In the application code, Application.ThreadException and AppDomain.CurrentDomain.UnhandledException are redirected to a method that writes the error log to disk, saves the screenshot to disk, and displays a friendly dialog box.

But when this error occurs, none of these three things happen. All I get is in the event viewer:

EventType clr20e3, P1 myapp.exe, P2 4.0.0.0, P3 47d794d4, P4 mscorlib, P5 2.0.0.0, P6 471ebc5b, P7 15e5, P8 27, P9 system.argumentoutofrange, P10 NIL

Given that the error only occurs after the application has been running for several hours, I wonder if this could be a memory leak problem. I searched a bit for "clr20e3", but only could find ASP.Net stuff. My application is a Windows Forms (.Net 2.0) exe, using quite a few builds - both in C # and in some unmanaged C ++.

I suppose this could also be a mistake in the error handling method. As some answers show, I can try registering at the beginning of the error handler (but considering that this is pretty much what I do anyway ...).

Any help that solves this problem will be greatly appreciated - whether it be a solution or a suggestion on how to find out what is the main cause of the problem.

UPDATE: the main cause of the original error was access to an array with a negative index (this was the system.argumentoutofrange parameter). Why this was not trapped is a bit of a mystery to me, but considering that both exceptions were sent to the same processing code, I wonder if there could be a condition when (for example) both were called and fought for the resource ( e.g. log file)?

I managed to prove this by doing EventLog.WriteEntry first of all in the error handling code. By adding a flag to prevent re-writing in error handling, I no longer have a problem ...

+4
source share
3 answers

Just shoot in the dark here - is it possible that an ArgumentOutOfRangeException is actually a handler selected from your exception?

In addition, you did not say what type of application is in question - Application.ThreadException only affects WinForms threads, so if it is not a GUI application, it is useless. (See the Notes Section in the MSDN Documentation )

+1
source

Have you checked if ArgumentOutOfRangeException selected from the handler itself? It might be worthwhile to make a simple entry in the event log or trace when writing your exception handler and confirm that you are actually clicking on it.

Edit: Information about event logging can be found at:

http://support.microsoft.com/kb/307024

+1
source

Do you call Application.Run () more than once? This will show the same symptoms that you describe. You must write your own ApplicationContext class as a workflow. Only my 0.02 US dollars are adjusted for inflation.

0
source

Source: https://habr.com/ru/post/1276861/


All Articles