Question: I want to handle all the unhandled exceptions in my `Progress` class, in which I wrote some code for error logging:

```
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        try
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new LoginPoint());
        }
        catch (Exception myException)
        {
            //log the unhandled exceptions.                
        }
    }
}

```

But the exceptions in the `BackgroundWorker` are not being handled correctly:

```
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    BackgroundWorker worker = sender as BackgroundWorker;
    throw new Exception("TEST EXCEPTION!");
}

private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    if (e.Error != null)
    {
        throw new Exception("I GOT THE EXCEPTION");
    }
}

```

I want the exception *"I GOT ..."* to be handled in my `Progress` class, but the system's exception dialog appears when I run (not debug) the application.

Answer: 
in the program.cs do this:

```
[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException;
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
    Application.Run(new Form1());
}

static void AppDomain_UnhandledException(Object sender, UnhandledExceptionEventArgs e)
{
    MessageBox.Show(((Exception)e.ExceptionObject).Message, "AppDomain.UnhandledException");
    Environment.Exit(-1);
}

```

your form code should work with that, and you should get the `AppDomain.UnhandledException` MessageBox in Run-Mode (ctrl+F5)
My approach would probably be event handlers. The problem you face is communication across threads, which is a notorious bummer! You should research threads and invoking to learn more about this. However, you can use events and event handlers to safely communicate between your worker and primary threads. Here's a brief example :

```
public delegate void ExceptionHandler(Exception ex);

public class Worker : BackgroundWorker
{
    ExceptionHandler Handler { get; set; }

    public Worker(ExceptionHandler handler)
    {
        Handler = handler;
    }

    protected override void OnDoWork(DoWorkEventArgs e)
    {
        for (var i = 0; i < (int)e.Argument; i++)
        {
            if (i%2 != 0) continue;

            try
            {
                throw new ArgumentException(String.Format("{0}:{1}", i, "TEST EXCEPTION"));
            }
            catch (Exception ex)
            {
                if (this.Handler != null)
                    Handler.Invoke(ex);
            }
        }
    }
}

class Program
{
    public static void HandleException(Exception ex)
    {
        Console.WriteLine(ex.Message);
    }

    static event ExceptionHandler Handler;

    static void Main(string[] args)
    {
        Handler = new ExceptionHandler(HandleException);
        var worker = new Worker(Handler);
        worker.RunWorkerAsync(100);

        Console.ReadLine();
    }
}

```

Expected output in your console window would be :

```
0:TEST EXCEPTION
2:TEST EXCEPTION
4:TEST EXCEPTION
6:TEST EXCEPTION
etc etc

```

Hope that proves helpful and even if it's not the answer you're looking for, hopefully it will help you somehow.