The problem is that you are doing all your work on the user interface thread. To re-draw the user interface, you will typically need to download Windows messages. The easiest way to fix this is to specify a progress bar for the update. Calling Control.Update will cause any pending drawing to execute synchronously.
progressBar1.Maximum = 50; for (int i = 0; i < 50; i++) { progressBar1.Value++; progressBar1.Update(); } MessageBox.Show("Finished"); progressBar1.Value = 0;
Other methods that may work are to use a background thread (with all the additional Control.Invoke calls necessary to synchronize with the user interface thread). DoEvents (as mentioned earlier) should also work - DoEvents will allow your window to process messages again for a time that may allow your paint messages. However, it will pump all the messages in the message queue so that it can cause unwanted side effects.
source share