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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:46:47+00:00 2026-05-26T18:46:47+00:00

I’m not the best with multi-threading, and this is a bit complicated, so hopefully

  • 0

I’m not the best with multi-threading, and this is a bit complicated, so hopefully I can explain it well.

Basically, what I have is a BackgroundWorker task, and inside it are several calls to retrieve information from a website. There may be a better way to do this, but I can’t think of one. The reason I’m doing this is because I want to have a single event for when all of the calls to the website (and the subsequent processing of the information) are completed.

This is basically what I have going on:

private void loadContent() {
    BackgroundWorker worker = new BackgroundWorker();
    worker.DoWork += delegate(object sender, DoWorkEventArgs e) {
        getAndProcessInformation(desiredInformationName);
        getAndProcessInformation(someOtherDesiredInformationName);
    };
    worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) {
        MessageBox.Show("Finished!");
        Dispatcher.BeginInvoke(() => { progressBar(false); });
    };
    worker.RunWorkerAsync();
}
private void getAndProcessInformation(string theInformationIWant){
    Fetcher dataFetcher = new Fetcher(); //Fetcher is a custom class that reads information from a web server
    dataFetch.receivedData += delegate(DataResponseArgs args) {
        //Process some data
    };
    dataFetch.requestData(theInformationIWant);
}

So, what happens is that the RunWorkerCompleted is called right after the two getAndProcessInformation methods are called, and before the data is actually finished processing. Is there any way I can make RunWorkerCompleted only run once the processing in the methods is actually finished?

Now, I can see that the BackgroundWorker isn’t really necessary, since the processing is actually already being done in a separate thread, but I don’t know any alternative that would let me get the desired result of having one event triggered when all of the processing has been completed. So, I guess this is really two questions; Should I continue using the BackgroundWorker, and, if so, how do I fix it, or, if not, what’s the alternative?

  • 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-26T18:46:48+00:00Added an answer on May 26, 2026 at 6:46 pm

    If your Fetcher is already creating its own thread, Using BackgroundWorker doesn’t make much of a sense like you already figured out.

    As you have not shared the implementation of Fetcher. It should probably be something like this if you want to stick with what you already have

    private void getAndProcessInformation(string theInformationIWant){
        Fetcher dataFetcher = new Fetcher(); 
        var eventHandle =  new ManualResetEvent(false);
        dataFetch.receivedData += delegate(DataResponseArgs args) {
            //Process some data
            eventHandle.Set();
        };
        dataFetch.requestData(theInformationIWant);
        eventHandle.WaitOne();
    }
    

    This way the function getAndProcessInformation wont return until processing has been done. Only one Fetch will be working at a time.

    If you want all Fetchers to work in parallel, you have remove the WaitOne and have the getAndProcessInformation return the wait handle. Then in DoWork you can do one wait for all handles to be signalled.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.