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

The Archive Base Latest Questions

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

*Note:Rephrasing my question based on user’s comments. Need help on how to use .Net’s

  • 0

*Note:Rephrasing my question based on user’s comments.

Need help on how to use .Net’s Backgroundworker thread for the following purpose to increase UI responsiveness and performance in my .Net winforms application.
When user clicks “Calculate” button in UI form,I’m doing this:

1.Get a list of categories C from database[this is typically around 10]

2.For each category C, do the following:

a.Call a third-party library, do some processing and calculate category price.

b.Get a list of products[This is typically around 800].

c.For each product, calculate its price using its category price from above.

d.Update this price of each product back in the database using a stored proc.

3.Update the progress back[or report any error message] to a form in UI.

FYI,I want to use Backgroundworker for steps #c and #d above.

I tried using Backgroundworker in my method.I put calls to InitializeBackgroundworker() and RunWorkerAsync() in the outermost loop[ie. step 2].But looks like, Backgroundworker is getting invoked only for the first category.What am I missing here?

So my question is, where do I make a call to InitializeBackgroundworker() and RunWorkerAsync()?
And how do I make sure these 2 methods get called for each category?

Thanks for reading.

  • 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-16T17:27:59+00:00Added an answer on May 16, 2026 at 5:27 pm

    Try something like this for a start.

    BackgroundWorker worker = new BackgroundWorker();
    
    void SomeForm_Load(object sender, EventArgs e)
    {
      // setup the BackgroundWorker 
      worker.WorkerReportsProgress = true;
      worker.DoWork += new DoWorkEventHandler(worker_DoWork);
      worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
      worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_Completed);
    }
    
    void SomeControl_Click(object sender, EventArgs e)
      List<Category> categories = DataBase.GetSomeCategories(); // [1] get Category list
      // start the BackgroundWorker passing in the categories list.
      worker.RunWorkerAsync(categories);
    }
    
    void worker_DoWork(object sender, DoWorkEventArgs e)
    {
      int progress = 0;
      var categories = e.Argument as List<Category>;       
      categories.ForEach(category =>                         // [2] process each Category
      {
        ThirdPartyControl.DoSomeProcessing(category);        // [2.a]
        var categoryPrice = CalculateCategoryPrice(category);
        var products = GetListOfProducts(category);          // [2.b] 
        products.ForEach(product =>                          // [2.c] process each Product
        {          
          var productPrice = CalcProductPrice(categoryPrice); 
          DataBase.UpdateProduct(product, productPrice);     // [2.d]
          progress = //...calculate progress...
          worker.ReportProgress(progress);                   // [3]
        });
        progress = //...calculate progress...
        worker.ReportProgress(progress);                     // [3]
      });
      worker.ReportProgress(100);
    }
    
    void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
      //...update some UI stuff...
      progressBar.Value = e.ProgressPercentage;
    }
    
    void worker_Completed(object sender, RunWorkerCompletedEventArgs e)
    {
      //...all done...
    }
    

    You can always break it into multiple BackgroundWorkers as your understanding increases.

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

Sidebar

Related Questions

Note: The following is just an example. I'm pretty new to ASP.NET MVC and
Note that I'm a complete SQL noob and in the process of learning. Based
NOTE: Please ignore my use of MultivaluedMap instead of multiple vargs String...args . Is
Note: This is a follow-up to an answer on a previous question . I'm
Note: I do NOT want to use any framework. The goal is just to
Note: I will not be using salts. Thanks for your advice though! I'm testing
Note: I'm more interested in understanding general Go concepts/patterns, rather than solving this contrived
Note, this might perhaps be best suited on serverfault.com, but since it is about
Note: I am not sure if this is better here, or at superuser, but

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.