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

  • Home
  • SEARCH
  • 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 8574865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:34:16+00:00 2026-06-11T19:34:16+00:00

My Console App uses System.ComponentModel.BackgroundWorker for threading purposes: System.ComponentModel.BackgroundWorker backgroundWorker = new System.ComponentModel.BackgroundWorker(); backgroundWorker.DoWork

  • 0

My Console App uses System.ComponentModel.BackgroundWorker for threading purposes:

System.ComponentModel.BackgroundWorker backgroundWorker = new System.ComponentModel.BackgroundWorker();

backgroundWorker.DoWork += (sender, e) =>
     ReportStatus(worker, status, result, e);
backgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
backgroundWorker.RunWorkerAsync(worker);

As you can see that I am passing “worker” as an argument inside RunWorkerAsync.

What I am trying to achieve is that if there is an exception inside ReportStatus method I need the same “worker” object so that I can perform some operation (Call a service to notify that workers exception)

private void ReportStatus(Worker worker, Status status, WorkResult result,System.ComponentModel.DoWorkEventArgs arg)
{
    var proxy = new PreparationServiceProxy(new NetTcpBinding(), new EndpointAddress(PreparationEngineState.ServiceAddress));
    try
    {
        proxy.ReportStatus(worker, status, result);
        proxy.Close();
    }
    catch (Exception)
    {
        arg.Result = worker;
        proxy.Abort();
        throw;
    }
}

In my exception block (I am not sure if this is the correct way!) I am assigning the worker to the Result so that I can get the same worker back when the RunWorkerCompleted method (backgroundWorker1_RunWorkerCompleted) is executed :

private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{

    if (e.Error != null)
    {
        Worker worker = e.Result as Worker; // At this point I get an exception!
    }
}
  • 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-06-11T19:34:17+00:00Added an answer on June 11, 2026 at 7:34 pm

    It’s because you re-threw the exception. BackgroundWorker sees that as an exception unhandled by the DoWork handler and re-throws it back on the other thread when you get the Result value.

    If you don’t want it to do that, remove the throw in your catch in the DoWork handler.

    if you passed the worker object into the BackgroundWorker, why don’t use just use what you passed in in an exception handler wrapping the call to Result or in the block that tests Error? e.g.:

            if (e.Error != null)
            {
                worker.DoSomething(); // no access of Result
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title states, I have a C# console app which uses interop to
I have a console app built on .NET 4 that uses the HttpClient library
We have a simple console app that uses EF 4 to process data; read
I've written a simple console app which uses JPA to connect to a MySQL
I have a console app that uses 20 or so threads to connect to
I have a console app, let's call it Test.Console . This app uses a
I have a C# app which uses a System.Diagnostics.Process to run another exe. I
I have a C# app that runs a jar file and uses the System.exit
I cannot find out which font the console app uses by default? Is it
I've got console app in Xcode which uses Core Data and should get one

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.