I have a problem in a WPF application. I wrote this code:
public partial class App : Application
{
public App()
{
AppDomain.CurrentDoma
You can also use Application.Exit()
or System.Environment.Exit(exitCode)
to immediately shut down your application after you have shown your error dialog box.
You can avoid multiple messageboxes by initializing a static boolean firstTime
to true
and use the code within the Exception handler:
void MyHandler(object sender, UnhandledExceptionEventArgs e) { if (firstTime){ Exception exception = e.ExceptionObject as Exception; MessageBox.Show(exception.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); firstTime = false; }else{ // Now kill the process.... } }
To terminate the process do this, within the MyHandler
:
System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess(); proc.Kill();