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

  • Home
  • SEARCH
  • 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 6566853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:15:57+00:00 2026-05-25T14:15:57+00:00

Edit : I solved the problem by creating the background worker by creating it

  • 0

Edit: I solved the problem by creating the background worker by creating it in code instead of dragging and dropping in design.

Now I know how to use a background worker.

Question

It’s my first time using a BGWorker, so here’s my issue…

  • The cursor doesn’t change to “Wait”.
  • The progress bar doesn’t update.
  • RunWorkerCompleted isn’t invoked.

But the textbox does update.

Am I doing something wrong ?

The Code

using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace BGWorker
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
            progressBar1.Minimum = 0;
            progressBar1.Value = 0;
            progressBar1.Maximum = 100;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            backgroundWorker1.RunWorkerAsync();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            for (int i = 1; i <= 100; i++)
            {
                textBox1.AppendText(i.ToString());
                textBox1.AppendText("\n");
                backgroundWorker1.ReportProgress(i);
            }
        }

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

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                label1.Text = e.Error.Message;
            }

            else
            {
                label1.Text = "All Done !";
                Cursor.Current = Cursors.Default;
            }

        }
    }
}

Thanks.

  • 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-25T14:15:57+00:00Added an answer on May 25, 2026 at 2:15 pm

    I agree with pst.

    1. Always create your worker in the code behind – dragging and dropping on the form is never a good idea
    2. You never access UI elements from the DoWork. You can only do this from the ReportProgress and RunWorker Completed Events
    3. Your if statement segment should contain your most common path with the least common path in the else.

      private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
      {
          StringBuilder sb = new StringBuilder();
          for (int i = 1; i <= 100; i++)
          {
              sb.AppendLine(i.ToString());
              backgroundWorker1.ReportProgress(i);
          }
          e.Result = sb.ToString();
      }
      
      private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          if (e.Error == null)
          {
              textbox1.Text = e.Result.ToString();
              label1.Text = "All Done !";
              Cursor.Current = Cursors.Default;
          }
      
          else
          {
              label1.Text = e.Error.Message;
          }
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

edit #2: Question solved halfways. Look below As a follow-up question, does anyone know
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
HI. I know this is simple question but when I use FirstPersonTestImage.Save(IIdComboBox.Text + -
EDIT: I solved #2 below by simply changing the background of the TextView's parent
I have a question about GUI design, specifically with Java Swing and creating clean
I'm testing some code that needs to use FileInfo and DirectoryInfo object and, instead
EDIT: Problem solved by using $i+1 in function call. I have trouble using variables
Edit: I solved my problem but if you have anything to add please do.
I know I can solve the following problem just by creating a custom class,
edit: I was trying to solve a spoj problem. Here is the link 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.