It's probably executing the code quicker than you expected ( are your sure it takes 4 sec to execute) and this is why the dialog is probably being hidden immediately.
UI elements are drawn and updated through the main thread message loop. When the main thread runs your code it isn't able to handle the messages. The messages wait till the main thread is free. By calling DoEvents you allow the main thread to process UI related messages.
It'll be a trade off between how often you want the Progress to update and how much you want to slow down the actual process.
I would think updating the progress bar every second is enough, so experiment with the placement, although the results will probably be different with different devices.
If the process that is taking a long time has no other UI updates, you could run it in a separate thread, the progress bar will then keep running in the main thread. Or you could look at the RunOnGuiThread if there are some UI updates (not tried that though).
I have tried to call DoEvents inside a timer but had no joy with it - even when setting the timer interval as low as 1ms (went to max 1000ms). Placed some DoEvents calls inside some of the nested for/next loops inside my code and could then see the ProgressDialog....Thought that by using a timer the UI related massages (in this case the ProgressDialog) would have had sufficient time to update- especially with the interval set to 1000ms?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.