9
votes

My application is built in WPF but it includes some WinForms components that we have written. When an exception is unhandled in one of the WinForms components it crashes the application.

I have implemented DispatcherUnhandledException for WPF events. This is good because it allows me to display an error and mark the exception as Handled to avoid the crash.

Can I do something similar with the non-WPF exceptions. I was hoping for the standard WinForms dialog that used to come up and allow the user to continue or quite the application?

Edit: WinForms exceptions do get caught in DispatcherUnhandledException but setting e.Handled to true doesn't stop the application from crashing.

1
can you show some code on how you are showing/using the Windows Forms forms ?Davide Piras
DispatcherUnhandledException should catch any unhandled exceptions in the UI thread. Do your WinForms components use other threads? Or are you accessing them from other threads by mistake?svick
@DavidePiras They are hosted in a WindowsFormsHost control in the WPF markup. E.g. windowsFormsHost.Child = [instance of WinForms control]Alan Spark
@svick Sorry, I should have made my question clearer. The WinForms exceptions were caught in DispatcherUnhandledException but setting e.Handled to true didn't stop the crash.Alan Spark

1 Answers