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 7533181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:40:00+00:00 2026-05-30T05:40:00+00:00

I have a windows from application with a program.cs code like this: static class

  • 0

I have a windows from application with a program.cs code like this:

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.ThreadException += (sndr, evnt) => 
        { 
            MessageBox.Show("An error occur. Please contact your administrator.\nError description: " + 
                evnt.Exception.Message + "\nStack trace:\n" + evnt.Exception.StackTrace, 
                evnt.Exception.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); 
        };
        Application.Run(new frmLogin());
    }
}

But when an exception is thrown inside the BackgroundWorker.DoWork event, the Application.ThreadException didn’t catch it.

How can the Application.ThreadException catch an exception from a different thread created by a BackgroundWorker?

I know catching errors in the Application.ThreadException is not a good practice but we only use it as our last level of error catching.

My code is in C#, framework 4, build in VS2010 Pro.

Please help. Thanks in advance.

  • 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-30T05:40:01+00:00Added an answer on May 30, 2026 at 5:40 am

    See this question: BackgroundWorker exceptions don’t get propagated like that, so you can’t catch them in ThreadException.

    BackgroundWorkers that throw exceptions call RunWorkerCompleted as usual, but set the Error property on the event arguments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, within the Program.Program() static constructor I have this code: AppDomain.CurrentDomain.UnhandledException += (s, eargs)
I have seen examples of printing from a windows application but I have not
I have a Windows application that has 2 Forms . From one form I
I have idea to write errors from my application to the Windows Event Viewer
I have a site that requires Windows Authentication the application obtains the credential from
I'm coming at this from the Windows world... On Windows, we have Windows Installer
I have window form in my WPF Application when I open new window from
I have been experimenting with sending messages from two .NET Windows Forms applications using
We have an issue using the PEAR libraries on Windows from PHP . Pear
As you may have known that I switched from ubuntu to windows from my

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.