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
Thread.StartandThread.Joinis not the way to do it – that basically blocks your UI thread again.Application.DoEventsisn’t the way to go either – you really do want a separate thread.You could then use
Control.Invoke/Control.BeginInvoketo marshal back to the UI thread, butBackgroundWorkermakes 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
RunWorkerCompletedevent. TheReportProgressmethod andProgressChangedevent are used to handle updating the progress bar. (The UI subscribes to ProgressChanged, and the task calls ReportProgress periodically.)