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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:22:08+00:00 2026-05-26T10:22:08+00:00

I have a Thread processing a binary file and storing it in a datatable.

  • 0

I have a Thread processing a binary file and storing it in a datatable.
While processing i am updating the progress bar with the current stream position.
My problem is; in the Thread I have a finally{} block, and in that I set the progressbar value to the max allowed value, then i run Application.DoEvents(); then I display a MessageBox, but my MessageBox always appears before the Progressbar fills.

problem

here is the applicable code

here is a video showing the issue

I have created a small application to demo the use of a BackgroundWorker instead of a Thread. Here is the code

I am seeing the same ‘error’ ( I am Hesitant to call this an error, more a Usability issue ) As you can see I have also added a dirty little logger there. The output at the end of the log file is:

27/10/2011 4:58:29 PM – Progress Entered

27/10/2011 4:58:29 PM – Progress Changed to 79661

27/10/2011 4:58:29 PM – Progress Entered

27/10/2011 4:58:29 PM – Progress Changed to 79661

27/10/2011 4:58:29 PM – Complete Entered

27/10/2011 4:58:29 PM – Events Done

27/10/2011 4:58:30 PM – Message Shown

So there is not a problem with the order in which the commands are being executed… is my only real solution to add a delay before displaying the messagebox?

  • 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-26T10:22:09+00:00Added an answer on May 26, 2026 at 10:22 am

    I would try replacing the Application.DoEvents(); with a simple Thread.Sleep(100). The documentation around DoEvents does not seem to indicate whether you are allowed to call it from another, non-UI thread. By using Thread.Sleep instead, you’re delaying the message box popup and allow the UI thread to process normally.

    An alternative method to having the worker background pop up a message box is to use an event, and invoke the subscribed delegates on the UI thread (just like you do for the progress bar).

    In fact, if you wanted, you could probably rewrite your thread code to use the BackgroundWorker object, and subscribe to the ProgressChanged and RunWorkerCompleted events. Your actual thread code would be responsible for calling the ReportProgress method to fire the ProgressChanged event to update your progress bar.

    Response to update

    After looking at your new code, you’re never setting the progress bar to the maximum value when your worker completes. In worker_RunWorkerCompleted add progressBar1.Value = progressBar1.Maximum; before you show the message box. That should update the progress bar to maximum before the message box pops up.

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

Sidebar

Related Questions

My Goal I would like to have a main processing thread (non GUI), and
I have an application processing network communication with blocking calls. Each thread manages a
I have a simple UDP server that creates a new thread for processing incoming
I have a thread that is doing some processing. I would like to be
I have a processing thread that I use to fill a data buffer. Elsewhere
I have a thread thats analyzing a file and making transactional calls to the
I have an architecture that reads packets from a packetized binary file, assigns each
I'm working on an image processing application where I have two threads on top
I have thread exception handler which saves the exception stack trace and should close
Suppose I have thread 1, the main window UI thread and thread 2, a

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.