Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 606593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:16:14+00:00 2026-05-13T17:16:14+00:00

I have a problem in a WPF application. I wrote this code: public partial

  • 0

I have a problem in a WPF application. I wrote this code:

public partial class App : Application
{
    public App()
    {
        AppDomain.CurrentDomain.UnhandledException += new 
            UnhandledExceptionEventHandler(MyHandler);
    }

    void MyHandler(object sender, UnhandledExceptionEventArgs e)
    {
        Exception exception = e.ExceptionObject as Exception;
        MessageBox.Show(exception.Message, "ERROR",
                        MessageBoxButton.OK, MessageBoxImage.Error);
    }

    ...
}

but when a unhandled exception happens, a lot of MessageBox appear to the screen (the exception happens in a timed routine) and after closing one of them, Windows signals that there is an unhandled exception.

How can I avoid multiple MessageBoxes?
How can I avoid the message of an unhandled exception?
How can I terminate the application after the exception?
As you can easily suppose, I would like to show a message (but only one) with my MessageBox and then terminate the application without any other message.

In a previous question related to this argument, Kyle Rozendo told me to use DispatcherUnhandledException. Is it necessary or the code I written is sufficient?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:16:15+00:00Added an answer on May 13, 2026 at 5:16 pm

    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();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with WPF - I'm quiet new in this smart technology. So
I have a WPF application, and I subscribe to the event AppDomain.AssemblyResolve (this event
I have a problem with my WPF application. I have a datagrid (Wpf Toolkit),
I have a problem with XamDataChart in a WPF application. When I add the
While debugging a problem in a WPF application, I have noticed that the TwoWay
I have an WPF application. The problem: need program(daemon, service) that send signals by
Well, the problem is as follows: I have a WPF Application built using the
i have a problem i make a wpf application its running well.but i want
I have an application written in wpf, which downloads some webpages, parses html code
I want my WPF application run just one time. I have no problem with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.