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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:47:29+00:00 2026-06-10T14:47:29+00:00

After the background worker is done doing its process, I want to change the

  • 0

After the background worker is done doing its process, I want to change the text on certain labels on the form.

Here’s the Button that fires the backgroundworker:

private void btnProcessImages_Click(object sender, EventArgs e)
        {
            DialogResult processImagesWarnMsg = MessageBox.Show("You're about to process images, are you sure?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);

            if (processImagesWarnMsg == DialogResult.Yes)
            {
                DisableAllButtons();

                if (!processImagesWorker.IsBusy)
                {
                    processImagesWorker.RunWorkerAsync();
                }
                //The problem here is that the below will run BEFORE the worker is complete. Where should I place the below method in my code? 
                //ResetDirectoryStatistics();
            }
        }

Here’s the method that changes text for the labels on the form:

private void ResetDirectoryStatistics()
        {
            lblSelectedDirectory.Text = "N/A";
            lblTotalNumberOfFilesInDirectory.Text = "N/A";
            lblTotalNumberOfSupportedFilesInDirectory.Text = "N/A";
            lblTotalNumberOfUnsupportedFilesInDirectory.Text = "N/A";
            lblTotalNumberOfPoliciesInDirectory.Text = "N/A";
        }

When dealing with the background worker, where should I place the ResetDirectoryStatistics method? I cannot place it in the “DoWork” method of the backgroundworker because that would be cross-threading. And if I place the method right after processImagesWorker.RunWorkerAsync();, it’ll execute itself before RunWorker is complete.

  • 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-10T14:47:31+00:00Added an answer on June 10, 2026 at 2:47 pm

    You should call your method in the RunWorkerCompleted event of the background worker. This event uses the UI thread, so no cross-threading issue to fear.

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

Sidebar

Related Questions

Is it necessary to dispose off the Background Worker after I have done the
I have a background worker that stops after 100 iterations. Like this: BackgroundWorker bgWorker
I have a simple program which is able to change the background color after
After certain R#-recommended edits R# colors the background of blocks of code in a
Background: I want to show the time and date uptill only 1 week. After
I have a method what I want to call after -viewDidLoad and in background
My application has a few background worker, each doing different work. When I click
I have a windows form application in which i am using a background worker
I want to make the result (Returning result of the heavy process) accessible after
I need to blink between two colors:red and white. I've found that after $targetcss('background-color','red')

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.