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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:31:01+00:00 2026-05-29T06:31:01+00:00

I have got a StartCommand Class: public class StartCommand : ICommand { public void

  • 0

I have got a StartCommand Class:

public class StartCommand : ICommand
{
    public void Execute(object parameter)
    {
        //Fill Listview1
        ...
        //Here I want to increase the Progressbarvalue   

        //Fill Listview2
        ...
        //Here again and so far..       
    }
}

Execute Command will be executed, when clicking the Startbutton on my MainWindow.xaml (where’s also the progressBar).

What I want now, is updating the Progressbar on these places (look at Code), while the ListViews are loading. How do I set up the Backgroundworker?

I tried something like that:

public class StartCommand : ICommand
    {
        MainWindow mainWindow;

        public StartCommand(MainWindow mainWindow)
        {
             this.mainWindow = mainWindow
        }

        public void Execute(object parameter)
        {
            //Fill Listview1
            ...
            mainWindow.backgroundWorker1.RunWorkerAsync(10);  

            //Fill Listview2
            ...
            mainWindow.backgroundWorker1.RunWorkerAsync(20);      
        }
    }

MainWindow:

public partial class MainWindow : Window
{
    BackgroundWorker backgroundWorker1;

    public MainWindow()
    {
        InitializeComponent();
        InitializeBackgroundWorker();
    }

    private void InitializeBackgroundWorker()
    {
        backgroundWorker1.DoWork +=
            new DoWorkEventHandler(backgroundWorker1_DoWork);
        backgroundWorker1.RunWorkerCompleted +=
            new RunWorkerCompletedEventHandler(
        backgroundWorker1_RunWorkerCompleted);
        backgroundWorker1.ProgressChanged +=
            new ProgressChangedEventHandler(
        backgroundWorker1_ProgressChanged);
    }


    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;
        e.Result = UpdateProgressBar((int)e.Argument, worker);
    }

    private int UpdateProgressBar(int value, BackgroundWorker worker)
    {
        worker.ReportProgress(value);
        return Convert.ToInt32(progressBar.Value);
    }

    private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {

    }

    private void backgroundWorker1_ProgressChanged(object sender,ProgressChangedEventArgs e)
    {
        progressBar.Value = e.ProgressPercentage;
    }
}

}

Thats not working (This is only some Copy/Paste arrangement, cause I have no idea on how to accomplish that, working first time with Threads in WPF). But maybe u got now a better sight, of what I’m looking for..

  • 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-29T06:31:02+00:00Added an answer on May 29, 2026 at 6:31 am

    You have to choose: use one background worker to load all the listviews or use multiple background workers, each filling a listview.

    Currently you are trying to force the backgroundworker to start working on another job before the previous job has finished.

    To fix this quickly: put all the code to load the listviews in the DoWork handler.

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;
        // fill listview1
        worker.ReportProgress(percentageDone);
        // fill listview2
        worker.ReportProgress(percentageDone);
        // fill listview3
        worker.ReportProgress(percentageDone);
    }
    

    To use multiple Backgroundworkers create multiple Backgroundworkers:

    var bw1 = new BackgroundWorker();
    bw1.DoWork += ...;
    bw1.RunAsync(...);
    var bw2 = new BackgroundWorker();
    bw2.DoWork += ...;
    bw2.RunAsync(...);
    var bw3 = new BackgroundWorker();
    bw3.DoWork += ...;
    bw3.RunAsync(...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got below two public properties in my DataContract class. I want to
Have got an NSString *str = @12345.6789 and want to find out if there
I have got the following code from here to read an Excel file using
I have got a class which is called BaseCore which just runs all the
I have got a username [string] and I want to check the password for
I have got the list of Class Name as Follows: Type[] typelist = typeof(Sample.Students).Assembly.GetTypes();
I have got my own JAR () running via separated class loaders and one
I have got a form which is generated by model object. <%= form_for(@pages) do
I have got a List<Problem> which I want to export to a column based
I have got a variable called name here Name = $(this).attr(title); I need to

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.