I have an application where I have a handler for unhandled exceptions to show the user a nicer dialog and allow them to submit a report of the failure.
I originally had a Winforms dialog that came up and it was working ok. However I decided to update it to a WPF dialog to match everything else in the apps that has been upgraded to WPF and it is showing some strange behavior.
I originally had
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf Boom
and in the handler (msg is a constructed string message):
Dim d As New Dlg_Boom(msg)
d.ShowDialog()
Me.Shutdown()
When I switched to the WPF dialog, the dialog comes up, but then I immediately get the 'Program has stopped working' windows dialog.
I have also tried using both:
AddHandler Dispatcher.UnhandledException, AddressOf Boom
AddHandler Application.DispatcherUnhandledException, AddressOf Boom
With these I get the option to set e.Handled=True. If I leave it false, I get the not working dialog, if I set it to true it flashes my WPF dialog and immediately closes it.
It's like it's ignoring the fact that it's ShowDialog() and treating it like Show() and not waiting for it to return. Oddly if I put a messagebox right before the ShowDialog() call it works as expected and waits for it to return.
I'm very puzzled, anyone have any insight on this?
ShowDialog()call? Does it wait until you close the window? Is the exception coming from the main thread or a background task?