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 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

Ask A Question

Stats

  • Questions 542k
  • Answers 542k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use: SELECT p.id as a, p.url as b, t.id as… May 17, 2026 at 3:22 am
  • Editorial Team
    Editorial Team added an answer There are two parts to the problem First Issue You… May 17, 2026 at 3:19 am
  • Editorial Team
    Editorial Team added an answer I thought I'd show the regex approach, too. It doesn't… May 17, 2026 at 3:18 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

NOTE: XMLIgnore is NOT the answer! OK, so following on from my question on
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
Note : The code in this question is part of deSleeper if you want
Note The question below was asked in 2008 about some code from 2003. As
Note This is not a REBOL-specific question. You can answer it in any language.
Note: This was posted when I was starting out C#. With 2014 knowledge, I
NOTE: I am not set on using VI, it is just the first thing
Note that I am not asking which to choose (MVC or MVP), but rather
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
NOTE : I mention the next couple of paragraphs as background. If you just

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.