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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:24:57+00:00 2026-06-04T07:24:57+00:00

I am working on a windows application using c#. I have a form and

  • 0

I am working on a windows application using c#.

I have a form and a class having all methods .

I have a method in class in which i am processing some files in arraylist. I want to invoke progress bar method for this file processing but its not working.

Any help

PFB my code snippet:

public void TraverseSource()
{
    string[] allFiles1 = Directory.GetFiles(sourcePath, "*.xml", SearchOption.AllDirectories);

    var allFiles = new ArrayList();
    var length = allFiles.Count;
    foreach (string item in allFiles1)
    {
        if (!item.Substring(item.Length - 6).Equals("MD.xml"))
        {
            allFiles.Add(item);

            // Here i want to invoke progress bar which is in form
        }
    }
}
  • 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-04T07:24:58+00:00Added an answer on June 4, 2026 at 7:24 am

    You’ll want to use a BackgroundWorker component, in which the DoWork handler contains your actual work (the string[] allFiles1 part and beyond). It’ll look something like this:

    public void TraverseSource()
    {
        // create the BackgroundWorker
        var worker = new BackgroundWorker
                           {
                              WorkerReportsProgress = true
                           };
    
        // assign a delegate to the DoWork event, which is raised when `RunWorkerAsync` is called. this is where your actual work should be done
        worker.DoWork += (sender, args) => {
           string[] allFiles1 = Directory.GetFiles(sourcePath, "*.xml", SearchOption.AllDirectories);
    
            var allFiles = new ArrayList();
    
            foreach (var i = 0; i < allFiles1.Length; i++)
            {
                if (!item.Substring(item.Length - 6).Equals("MD.xml"))
                {
                    allFiles.Add(item);
                    // notifies the worker that progress has changed
                    worker.ReportProgress(i/allFiles.Length*100);
                }
            }
        };
        // assign a delegate that is raised when `ReportProgress` is called. this delegate is invoked on the original thread, so you can safely update a WinForms control
        worker.ProgressChanged += (sender, args) => {
           progressBar1.Value = args.ProgressPercentage;
        };
    
        // OK, now actually start doing work
        worker.RunWorkerAsync();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using c# .net windows form application. I have created a database which has
I have a Windows Form application that I'm working on and I have some
Greetings, I'm working in windows application using C#. I have typed-dataset called packetsDBDataSet and
I am working on Windows client application using c#, have two projects in my
I am working on windows. I have built a twitter application using the twitter
I'm working with a windows form application in C#. I'm using a socket client
I'm working with a windows form application in C#. I'm using a socket client
I'm working on a windows form application and I want to have a rich
As I am working on .Net windows form application, we're using MongoDB for back-end
I have a windows form control inside wpf application using a windows forms host.

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.