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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:44:45+00:00 2026-05-15T10:44:45+00:00

In almost all tutorials of BackgroundWorker the reportProgress event is handled like this (this

  • 0

In almost all tutorials of BackgroundWorker the reportProgress event is handled like this (this example is from MSDN http://msdn.microsoft.com/en-us/library/cc221403(VS.95).aspx)

private void bw_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;

  for (int i = 1; (i <= 10); i++)
  {
    if ((worker.CancellationPending == true))
    {
        e.Cancel = true;
        break;
    }
    else
    {
        // Perform a time consuming operation and report progress.
        // _results.Load() downloads XML and save the data to database
        System.Threading.Thread.Sleep(500);
        worker.ReportProgress((i * 10));
    }
  }
}

My function downloads XML and save it to database after parsing. I called this function below “// Perform a time consuming operation and report progress.” But won’t my function run 10 times?

Later i modified Load() adding to variables CountTotal (total number of results) and CountLoaded (number of results saved, it changes as the function progress).

private void bw_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;

  for (int i = 1; (i <= 10); i++)
  {
    if ((worker.CancellationPending == true))
    {
        e.Cancel = true;
        break;
    }
    else
    {
        // Perform a time consuming operation and report progress.
        _results.Load() downloads XML and save the data to database

        worker.ReportProgress((_results.CountLoaded * 10)); //i did something like this
    }
  }
}

The problem is that worker.ReportProgress executes after the completion of _results.Load(). How to solve this problem? Are the given examples on internet really bad because they are suggesting to call the function in a loop, or I got them wrong?

  • 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-15T10:44:45+00:00Added an answer on May 15, 2026 at 10:44 am

    Yes – that will execute Load 10 times. The intent in that example is to illustrate usage when you can estimate the overall workload, or report meaningful progress. They are just trying to simulate “some work” with progress indication.

    If you can’t do that, then just run it async (via BackgroundWorker) but show a scrolling infinite marquee or similar. Don’t do it 10 times ;p Alternatively, run Load, then report progress when you process the data. Assuming that takes some time. If all the time is in Load, then…

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

Sidebar

Related Questions

I'm following this tutorial for twitter4j: http://www.javacodegeeks.com/2011/10/java-twitter-client-with-twitter4j.html and I've gotten almost everything right. All
Almost all of the examples in the jQuery tutorials that I've read, usually use
I have tried almost all the solutions from SO but no success :(. I
ok, so I am stuck at the observer pattern here, almost all tutorials I
Why in almost all the tutorials or examples people do that: @Override public void
while going through video tutorials for mvc2 which i downloaded from microsoft's website, the
Almost all the activities in my application need to interact with a web server
Almost all of my JUnit tests are written with the following signature: public void
In almost all of my projects I have few files that are project wide
I have tried almost all the techniques to apply sticky footer to my site

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.