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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:54:05+00:00 2026-05-19T02:54:05+00:00

I have already implemented a functionnal application that parses 26 pages of html all

  • 0

I have already implemented a functionnal application that parses 26 pages of html all at once to produce an xml file with data contained on the web pages. I would need to implement a thread so that this method can work in the background without causing my app to seems unresponsive.

Secondly, I have another function that is decoupled from the first one which compares two xml files to produce a third one and then transform this third xml file to produce an html page using XSLT. This would have to be on a thread, where I can click Cancel to stop the thread whithout crashing the app.

What is the easiest best way to do this using WPF forms in VS 2010 ?

I have chosen to use the BackgroundWorker.

BackgroundWorker implementation:

public partial class MainWindow : Window
    {
        private BackgroundWorker bw = new BackgroundWorker();

        public MainWindow()
        {
            InitializeComponent();
            bw.WorkerReportsProgress = true;
            bw.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.LoadFiles();
        }

        private void btnCompare_Click(object sender, EventArgs e)
        {
            if (bw.IsBusy != true)
            {
                progressBar2.IsIndeterminate = true;
                // Start the asynchronous operation.
                bw.RunWorkerAsync();
            }

        }

        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            StatsProcessor proc = new StatsProcessor();
            if (lstStatsBox1.SelectedItem != null)
                if (lstStatsBox2.SelectedItem != null)
                    proc.CompareStats(lstStatsBox1.SelectedItem.ToString(), lstStatsBox2.SelectedItem.ToString());
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            progressBar2.IsIndeterminate = false;
            progressBar2.Value = 100;
        }

I have started with the bgworker solution, but it seems that the bw_DoWork method is never called when btnCompare is clicked, I must be doing something wrong… I am new to threads.

  • 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-19T02:54:06+00:00Added an answer on May 19, 2026 at 2:54 am

    If you’re new to threading I think the easiest to start with would be using a BackgroundWorker:

    • It uses another thread: You can asynchronously perform the HTML parsing while your app remains responsive
    • It supports cancellation: You can can cancel the XML to HTML conversion

    The BackgroundWorker is event-driven so it’s much easier to get your ahead around if you’re new to multi-threading. The .NET 4 Task library is much more flexible, but a little more involved to take advantage of especially with UI updates.

    Example:

    BackgroundWorker worker = new BackgroundWorker();
    worker.DoWork += new DoWorkEventHandler((o, args) =>
    {
        //Long running stuff here       
        Thread.Sleep(10000);
        string result = "Hi UI!";
        args.Result = result;
    });
    
    worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler((o, args) =>
    {
        if (args.Result != null)
        {
            SomeTextBox.Text = args.Result;
        }
    });
    
    worker.RunWorkerAsync();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First some background: I already have a Result class that I've implemented to carry
I have already implemented and tested the data structure and would now like to
I have already implemented some AJAX pagination in my Rails app by using the
I have already implemented a functionallity, when keeper automatically moves using breadth first search
I just finished reading this post: https://developer.yahoo.com/performance/rules.html#flush and have already implemented a flush after
Before I start: I'm programming for Iphone, using objective C. I have already implemented
I already have implemented JOOQ with Union Platform as a java based game server
I am trying to implement a linux shell that supports piping. I have already
My issue is simple. I have already implemented a tab system, and I'd probably
In my Android app, I have some data that needs to be synced daily

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.