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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:31:24+00:00 2026-06-14T14:31:24+00:00

How can I fix this issue ? I am expecting the progressbar to load

  • 0

How can I fix this issue ?

I am expecting the progressbar to load during process untill process it is done

Here is my code:

private void btnProcess_Click(object sender, EventArgs e)
    {
        backgroundWorker.WorkerReportsProgress = true;
        backgroundWorker.ProgressChanged += backgroundWorker_ProgressChanged;
        backgroundWorker.DoWork += backgroundWorker_DoWork;

        backgroundWorker.RunWorkerAsync();
    }

    private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        //start transaction
        DoTransaction();
    }

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

My transaction function:

private void DoTransaction()
    {
        string pathIdentifier;
        pathIdentifier = func.checkthePathFile();
        if (pathIdentifier == null)
        {
            MessageBox.Show("Path has no yet been specified!");
        }
        else
        {
            //create xml base from user inputs
            XElement transactXML = new XElement("Transaction",
                new XElement("CardNumber", txtCardNum.Text.Trim()),
                new XElement("ExpireDate", txtExpDate.Text.Trim()),
                new XElement("Cardtype", txtCardType.Text.Trim())
                );

            //save xml to a file
            transactXML.Save(pathIdentifier + "/sample.xml");
        }
    }
  • 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-14T14:31:25+00:00Added an answer on June 14, 2026 at 2:31 pm

    How is the runtime supposed to know how far along your process is?

    You need to tell it by calling backgroundWorker.ReportProgress from the background operation. No magic here.

    MSDN: http://msdn.microsoft.com/en-us/library/ka89zff4.aspx

    Break down your process into meaningful chunks and ReportProgress whenever it makes sense to do so.

    public void DoTransaction()
    {
        part1();
        backgroundWorker.ReportProgress(25);
    
        part2();
        backgroundWorker.ReportProgress(50);
    
        part3();
        backgroundWorker.ReportProgress(75);
    
        part4();
        backgroundWorker.ReportProgress(100);
    }
    

    Edit Based on Posting of Transaction() function

    If you are not confident in writing multithreaded programs, then do not attempt to write multithreaded programs, even with the help of a BackgroundWorker which tries to abstract some of those details away from you.

    A few issues:

    Your provided Transaction() method attempts to launch a MessageBox and read the Text property of various controls from the background thread. This is going to cause problems as the runtime typically throws an Exception when UI elements are accessed from a thread other than the one which created them.

    If you really want to do the XML saving in the BackgroundWorker, you should validate the filename and directory, and save the Text properties to an intermediate object before setting up the BackgroundWorker and calling RunWorkerAsync.

    Furthermore, in my opinion, your Transaction method is not going to be time intensive enough to truly warrant a background thread. Even a relatively old PC will be able to create and save a 15 element XML file faster than you can blink. The runtime will probably waste more time marshalling data between the threads than it would to simply write the file out to disk. Just do your work in the button click event handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I fix the view of this twitter on my blogger blog. Here
Hope someone can fix this (hopefully simple) issue I'm having. We've got a Google
according to picture it report an object leak how can i fix this issue?
Can someone explain to me how I can fix this problem. I have two
I can't fix this problem on my listview template: i have the error as
How can I fix this? REGEX: //REGEX $match_expression = '/Rt..tt<\/td> <td>(.*)<\/td>/'; preg_match($match_expression,$text,$matches1); $final =
How can I fix this error, and install thin or other gems? $ sudo
The Term::Size-module jumbles up the encoding. How can I fix this? #!/usr/bin/env perl use
My navbar doesn't line up in IE... how can I fix this without using
Can anyone explain the output of this program and how I can fix it?

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.