views:

2013

answers:

2

I am trying to set up my WPF application so that when an exception goes unhandled, an error dialog pops up. In good ol' WinForms this was possible by adding

Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

To your Program.cs file and then showing whatever dialog you wanted in the event handling code. In WPF I've tried to use

app.Dispatcher.UnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException);

However, when I use Show() on my error-handling custom window, the application immediately goes to "blahblah.exe has stopped working..." and closes. If I use ShowDialog(), the window is usable until it's closed and then the same "...has stopped working..." dialog pops up and dies.

In WinForms, it seems that closing any error dialog would allow the app to continue running, depending on how severe the exception was. I can't seem to figure out how to properly do this in WPF.

Any ideas?

+4  A: 

You'll need to set Handled to true in the EventArgs.

Botz3000
A: 

In the Aplication.xaml.vb, this file has many ways to help to thems, storyborads and another stuffs, you neeed something like that in this file. works for me, hope so for you to

Private Sub Application_DispatcherUnhandledException(ByVal sender As Object, ByVal e As System.Windows.Threading.DispatcherUnhandledExceptionEventArgs) Handles Me.DispatcherUnhandledException

        Dim lWinError As New winError("Ocurrio un error no controlado en la aplicacion")
        lWinError.ShowDialog()
        e.Handled = True
    End Sub
Zach