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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:43:22+00:00 2026-06-04T13:43:22+00:00

I have a working solution that reports progress & text to a progress bar

  • 0

I have a working solution that reports progress & text to a progress bar and a label on the applications’s main form. I have now moved my worker methods to a class to they are accessible across multiple forms etc.

Within the worker methods are BW.ReportProgress() statements that push back the progress and text to the BackgroundWorker in the main form.

To give a better idea here is the file layout:

MainScreen.cs

List repSelected = new List();
XMLandRar xXMLandRar = new XMLandRar();

private void Rarbtn_Click(object sender, EventArgs e)
        {
            GetReps();

            //Run worker
            if (!CreateRarBW.IsBusy)
            {
                CreateRarBW.RunWorkerAsync();
            }
        }

//Worker
private void CreateRarBW_DoWork(object sender, DoWorkEventArgs e)
{
    xXMLandRar.RarFiles(repSelected);
}

//Progress reporting
private void CreateRarBW_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
    progBar.Value = e.ProgressPercentage;
    Statuslbl.Text = e.UserState.ToString();
}

Then my newly created Class that encompasses all of the worker methods and is to push progress to the main form.

XMLandRar.cs

public class XMLandRar
{
    public void RarFiles(List repSelected)
    {
        int step = 100 / repSelected.Count();
        int i = 0;
        //Iterate through list and run rar for each
        foreach (string rep in repSelected)
        {
            CreateRarBW.ReportProgress(i, "Raring files for " + rep);
            DirectoryExists(rep);
            ProcessRunner(rep);
            i += step;
            CreateRarBW.ReportProgress(i, "Raring files for " + rep);
        }
    }
}

The problem I am having is that in the XMLandRar class the CreateRarBW is not recognised (obviously) – how can I make a ReportProgress call to the BW in the main screen of the application?

  • 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-06-04T13:43:23+00:00Added an answer on June 4, 2026 at 1:43 pm

    Create an event in your XMLandRar class which you could subscribe to.

    This way the XMLandRar class doesn’t need to know or care about the UI or progressbar, it only cares about sending a message if anyone would listen. And there can also be more than one subscriber (let’s say if you want to report to the background worker and a log, maybe)

    Example:

    private void Rarbtn_Click(object sender, EventArgs e)
    {
        GetReps();
    
        //Run worker
        if (!CreateRarBW.IsBusy)
        {
            // This should be done once, maybe in the contructor. Bind to new event.
            xXMLandRar.ReportProgress += new EventHandler<XMLandRar.ProgressArgs>(xXMLandRar_ReportProgress);
    
            CreateRarBW.RunWorkerAsync();
        }
    }
    
    protected void xXMLandRar_ReportProgress(object sender, XMLandRar.ProgressArgs e)
    {
        // Call the UI backgroundworker
        CreateRarBW.ReportProgress(e.Percentage, e.Message);
    }
    
    public class XMLandRar
    {
        // Event handler to bind to for reporting progress
        public EventHandler<ProgressArgs> ReportProgress;
    
        // Eventargs to contain information to send to the subscriber
        public class ProgressArgs : EventArgs
        {
            public int Percentage { get; set; }
            public string Message { get; set; }
        }
    
        public void RarFiles(List repSelected)
        {
            int step = 100 / repSelected.Count();
            int i = 0;
            //Iterate through list and run rar for each
            foreach (string rep in repSelected)
            {
                // Report progress if somebody is listening (subscribed)
                if (ReportProgress != null)
                {
                    ReportProgress(this, new ProgressArgs { Percentage = i, Message = "Raring files for " + rep });
                }
    
                DirectoryExists(rep);
                ProcessRunner(rep);
                i += step;
    
                // Report progress if somebody is listening (subscribed)
                if (ReportProgress != null)
                {
                    ReportProgress(this, new ProgressArgs { Percentage = i, Message = "Raring files for " + rep });
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are working on complex solution that contains ASP.Net-based server-side and several client applications
Hi I have been working on a solution for days, and I've been trying
Iam working on small booking room system. In my solution I have a Reservation
I have working registration script the only problem is that i do not know
I have been working on a Windows Mobile app for a little while now
I am working on a form with a bunch of selection criteria that will
I want to display a progress bar while doing some work, but that would
I'm working on a project that produces quite a few pdf's through Crystal Reports.
We have a list of (let's say 50) reports that get dumped into various
I'm working on an app in JavaScipt, jQuery, PHP & MySQL that consists of

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.