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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:36:21+00:00 2026-05-21T12:36:21+00:00

I have an application where I am uploading a file in blocks. My front

  • 0

I have an application where I am uploading a file in blocks. My front end is WPF and I have a progress bar to show file upload progress (upload is done by separate thread, and the progress bar is in a separate form invoked by the child thread when uploading starts).

I found the total number of blocks in the file to set the maximum property of the progress bar.

Now for each block uploaded I increment the value of progress bar by 1.

But to my surprise, the progress bar starts to increment but never completes ( it stops showing progress after few blocks ).

Here is code for the thread responsible for uploading files:

 System.Threading.Thread thread = new Thread(
   new ThreadStart(
         delegate()
         {
              // show progress bar - Progress is the name of window containing progress bar
              Progress win = new Progress();
              win.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
              win.Show();

              // find number of blocks
             long BlockSize = 4096;
             FileInfo fileInf = new FileInfo(filename);
             long FileSize = fileInf.Length;
             long NumBlocks = FileSize / BlockSize;

             //set the min and max for progress bar
             win.Dispatcher.Invoke(
                  new Action(
                     delegate()
                     {
                            win.progressBar1.Minimum = 0;
                            win.progressBar1.Maximum = NumBlocks;                                                        
                     }
             ), System.Windows.Threading.DispatcherPriority.Render);

             //upload file
             while (true)
             {

                      // code to upload the file

                      win.Dispatcher.Invoke(
                          new Action(
                              delegate()
                              {
                                 win.progressBar1.Value += 1;
                              }
                      ), System.Windows.Threading.DispatcherPriority.Render);

             }
       }

Can someone help me analyze why is this happening.

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-21T12:36:22+00:00Added an answer on May 21, 2026 at 12:36 pm

    Here’s the issue:

    upload is done by separate thread, and
    the progress bar is in a separate form
    invoked by the child thread when
    uploading starts

    If that means your child thread created the form, then that’s the problem. Your child thread might be updating the progress bar values, but this will just invalidate the display, and not necessarily refresh the display. When a control’s display is invalidated, it simply records that it must redraw it’s display the next time it gets a chance. A refresh is when the control actually gets to render to the screen.

    A better approach is to create the progress bar form in the main thread.

    Your worker thread can then update the status, and your main thread will refresh the display.

    One thing to remember: if you’re updating a control that was created in a different thread, you must do so via the control’s dispatcher.

    var dispatcher = progressBar.Dispatcher;
    dispatcher.BeginInvoke(new Action( () => { progressBar.Value = currentProgress }));
    

    Edit after seeing the code

    All you need to do is move the creation of the progress variable so that it is instantiated by the main thread before the worker thread is created.


    Progress win = new Progress();
    win.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
    win.Show();
    System.Threading.Thread thread = new Thread(
       new ThreadStart(
             delegate()
             {
     // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application where I allow my users to upload a file of
I have an external application uploading a file to my rails web app. (Developed
I have an application uploading Access MDB (its file format) that I need to
I have an application that reads a CSV file with piles of data rows.
I have an application which extracts data from an XML file using XPath. If
I have small application that is uploading pictures to another website via webservice. My
I have developed an image uploading application that uses Flash to load an image,
I working on adding file uploading to my web application. I'm using an iframe
I have an application that will upload files from my client to a web
I have a Silverlight Application, that uploads file(s) to a Sharepoint Site. I got

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.