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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:41:18+00:00 2026-06-05T10:41:18+00:00

I have only a little experience with threading in WinForms. I am trying to

  • 0

I have only a little experience with threading in WinForms. I am trying to set a progress bar to 100, sleep for 2 seconds, and then hide the progress bar.

I have:

public void ProgressBarTimerStop()
{
    if (!AnyWorkersBusy())
    {
        if (InvokeRequired)
        {
            Invoke((MethodInvoker)delegate
            {
                ProgressBarTimer.Stop();
                Thread.Sleep(1000);
                Application.DoEvents();
                Thread.Sleep(1000);
                StatusToolStripProgressBar.Visible = false;
                StatusToolStripProgressBar.Value = StatusToolStripProgressBar.Minimum;
            });
        }
        else
        {
            ProgressBarTimer.Stop();
            StatusToolStripProgressBar.Value = StatusToolStripProgressBar.Maximum;
            Thread.Sleep(1000);
            Application.DoEvents();
            Thread.Sleep(1000);
            StatusToolStripProgressBar.Visible = false;
            StatusToolStripProgressBar.Value = StatusToolStripProgressBar.Minimum;
        }
    }
}

For the current problem I am experiencing InvokeRequired is false.

When I call the line:

StatusToolStripProgressBar.Value = StatusToolStripProgressBar.Maximum;

my watch window shows the value as set, but the GUI has not updated to reflect this. If I immediately sleep for a full two seconds the GUI does not update before sleeping.

If I call Application.DoEvents() without calling sleep beforehand — it appears to do nothing.

If I sleep, then call DoEvents — the GUI updates, and then I go back to sleep. This is correct, but I feel like my code is heinous.

Am I misunderstanding a key concept here?

EDIT: ProgressBarTimerStop is called only through “RunWorkerCompleted” event handlers.

I tried this, but it had no effect:

StatusToolStripProgressBar.GetCurrentParent().Refresh();
  • 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-05T10:41:19+00:00Added an answer on June 5, 2026 at 10:41 am

    The ‘key concept’ that you are missing is that updating the progress bar’s value does not immediately tell the progress bar to redraw itself.

    When you update the progress bar, the GUI thread repaints the progress bar on the next window repaint. This only happens when the GUI thread becomes free to do so. Normally this happens when the window receives a paint message from the operating system. This should be picked up by Application.DoEvents, but it could be that the message isn’t queued quickly enough to be picked up by DoEvents. You may be able to force it to with a Refresh call.

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

Sidebar

Related Questions

I am new to android and only have a little experience with HTML and
I have only a little question: Why the CFPreferences-API creates multiple files in my
I have very little programming knowledge; only a fair bit in Visual Basic. How
I have not done any large game development projects, only messed around with little
Trying to figure out how to manage/use long-living DB connections. I have too little
I have very little experience designing databases, and now I want to create a
I have some experience with programming, but I have very little experience when it
I have little experience with silverlight development still but with the potential of silverlight
I have only this, but my compiler says:Type mismatch: cannot convert from ArrayList to
I have only one class with many instances. Every instance is observer of couple

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.