Progress bar not showing until after task is completed

multithreading, winforms

Solution

`Thread.Start` and `Thread.Join` is not the way to do it - that basically blocks your UI thread again. `Application.DoEvents` isn't the way to go either - you really do want a separate thread.

You could then use `Control.Invoke`/`Control.BeginInvoke` to marshal back to the UI thread, but `BackgroundWorker` makes all this a lot easier. A search for "BackgroundWorker tutorial" yields lots of hits.

EDIT: To show the message when the worker has finished, use the `RunWorkerCompleted` event. The `ReportProgress` method and `ProgressChanged` event are used to handle updating the progress bar. (The UI subscribes to ProgressChanged, and the task calls ReportProgress periodically.)

Problem

I have been trying to get a progressbar set to marquee to keep moving while another function is running. After this function runs, I message would display (for this example) The only way I was able to get this working was with a background worker and then have a Do Loop until condition that runs in the main form until the operation is complete followed by my message box. This seems like a kludge way to accomplish this and a thread.start followed by a thread.join seems like a much nicer way to fix this. However, I was not able to get that working either. I have included a small demo program if anyone is interested. http://www.filedropper.com/progressbar Thanks

Original source