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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:48:07+00:00 2026-05-24T11:48:07+00:00

[EDIT] I edited my question with complete code and explanation and hope something can

  • 0

[EDIT]

I edited my question with complete code and explanation and hope something can give me clearer explanation.

I have the following Class that has a backgroundworker to track the percentage progress of a loop and update the percentage progress on a Label on ProgressWin’s XAML. The following code works perfectly. (My question is far below, after the code.)

public partial class ProgressWin : Window
{
    BackgroundWorker backgroundWorker1 = new BackgroundWorker();

    public ProgressWin()
    {
        InitializeComponent();
        InitializeBackgroundWorker();
        startAsync();
    }

    // Set up the BackgroundWorker object by 
    // attaching event handlers. 
    private void InitializeBackgroundWorker()
    {
        backgroundWorker1.WorkerReportsProgress = true;
        backgroundWorker1.WorkerSupportsCancellation = true;
        backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
        backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
        backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
    }

    private void startAsync()
    {
        backgroundWorker1.RunWorkerAsync();
    }

    public void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;

        for (int i = 1; i <= 10; i++)
        {
            System.Threading.Thread.Sleep(500);
            worker.ReportProgress(i * 10);
        }
    }

    // This event handler updates the progress.
    public void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        label1.Content = (e.ProgressPercentage.ToString() + "%");
    }

    // This event handler deals with the results of the background operation.
    public void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
         resultLabel.Content = "Done!";
    }
}

Here comes my problem, now instead of tracking the loop within the ProgressWin, I need to track the loop in my MainWindow:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        for (int i = 1; i <= 10; i++)
        {
            System.Threading.Thread.Sleep(500);
            ????.ReportProgress(i * 10);
        }
    }
}

And I have no idea where to go from here. I tried instantiating an object from ProgressWin and call the DoWork but I end up frozen the ProgressWin window.

  • 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-24T11:48:08+00:00Added an answer on May 24, 2026 at 11:48 am

    Due to the fact that the question was rewritten, i also rewrote my whole answer.

    To get this to work your MainWindowhas a ProgressWindow and should use it like a background worker:

    public partial class MainWindow : Window
    {
        private ProgressWindow _Progress;
    
        public MainWindow()
        {
            InitializeComponent();
    
            _Progress = new ProgressWindow();
            _Progress.ProgressChanged += OnProgressChanged;
    
        }
    
        private void OnProgressChanged(object sender, ProjectChangedEventArgs e)
        {
            //ToDo: Update whatever you like in your MainWindow
        }
    }
    

    To accomplish this your ProgressWindow should simply subscribe to the worker event and rethrow it:

    public partial class ProgressWin : Window
    {
        // Add this to your class above in your question
        public event ProgressChangedEventHandler ProgressChanged;
    
        // Change or merge this with your existing function
        private void backgroundWorker1_ProgressChanged(object sender, ProjectChangedEventArgs e)
        {
            var temp = ProgressChanged;
            if(temp !=null)
                temp(this, e);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following two scenarios (Edited just to complete the whole question and make
EDIT: I have edited my post... Working on a project (c#), I have a
Edit: From another question I provided an answer that has links to a lot
I just wonder that can we pass any type of class instances to view
I have edited this question to make it easier to understand. I have an
[EDITED: I left the original question below, with some more context and code to
another django question. I have a edit form like this. Look at current_status in
EDIT: I edited both the question and its title to be more precise. Considering
I am nearly ashamed to ask this, but... EDIT: I edited the question to
EDIT: Based on evolution of the problem, I edited this question. First of all,

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.