2

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 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

any way you can elaborate on how to actually assign the handler to the dispatcher? UnhandledException is not really a property of it..
It's not a property, but an event. Use the usual += syntax. Check out documentation: msdn.microsoft.com/en-us/library/…
poor choice of words, i meant that, that event is not available on my windows dispatcher object.
How is that? I mean, how do you know that it's not available?
actually, it is there, my mistake.
0

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); 

1 Comment

thanks, that is actually already implemented. but any WPF exception still nukes the container winforms app.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.