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 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 : Solved, there was a trigger with a loop on the table (read
Edit: I have solved this by myself. See my answer below I have set
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: From another question I provided an answer that has links to a lot
EDIT: This question is more about language engineering than C++ itself. I used C++
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
I am creating a simple gradient background by drawing a quad as follows: glMatrixMode
I have a design problem I'd like to solve. I have an interface, lets
Solved the problem see the bottom of my post. So I have a simple

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.