2
votes

so i came across this interesting article on WPF exception handling: http://srtsolutions.com/public/item/251263

it works by declaring DispatcherUnhandledException handler in xaml <application> node.

but what if a WPF window is launched from win forms application?

where can i declare a general exception handler?

The problem is that when WPF crashes, it brings down the whole WinForms app with it.

*Edit what if instead of launching the WPF window directly, i launched an "Application" which than defined a start window?? is that possible/advisable?

2

2 Answers

2
votes

Attach your handler to the <obj>.Dispatcher.UnhandledException event, where <obj> is any WPF control, or another DispatcherObject that is created on the same thread.

0
votes

I believe the traditional "global" exception handlers for Windows Forms would apply here:

Hook the thread exception as the first line in Main:

Application.ThreadException += new ThreadExceptionEventHandler(new ThreadExceptionHandler().ApplicationThreadException);