Lloyd said:
I'm using 2.0 beta 2, that might be the source of the problem.
Nah, its been part of the framework since the first version.
Anyway at the start of my application I register a global exception
handler: Application.ThreadException += someGlobalHandler;
The clue is in the class. The Application class is used to provide a
link between the Win32 message pump and the event handling mechanism in
Windows Forms. Windows has a restriction (which was in Avalon the last
time I checked) that a Window has thread affinity, so messages for a
window goes to the thread that created the window. The Application class
does all the grungy stuff to make this work (it does this with thread
and application context classes).
When the constructor of a form is called the window is not created.
Instead, the window is created when the Visible property is first set to
true. This is done when Application.Run is called. The handler for the
Visible property will register a Windows class and create the window.
The code that registers the class will use one of two windows
procedures - one is used for when you are running the application under
a debugger. The one used for the case when a debugger is not attached
puts exception handling around the code that handles messages. Hence an
exception thrown by any of your code will be eaten by this exception
handler. To get round this issue the thread context has an even (the
ThreadException event) that is called by this exception handler to give
you an opportunity to handle the exception.
All of this stuff is documented in my Managed C++ book.
anyway, wether I throw an exception in an auxiliary thread or in the
main GUI thread, the global handler seems never to be called ......
?!!?
You need to throw the exception *after* the window is called. If you
call it before the window is created (for example in the constructor)
then the Windows Form object will not be 'attached' to the windows
procedure that I mentioned above.
Richard