When do I know to call DoEvents?

If I am fixated on a lengthy operation (say, processing files) and I want to update the progress bar, I need to use DoEvents from what I can understand.

But calling it during each function cycle leads to the fact that the animation of the progress is played very quickly (or slowly, depending on the operation). I understand that this is because DoEvents allows the progress bar to "breathe" due to the lack of a better word, causing it and the rest of the form to be updated.

My question is, how do you know it should be called DoEvents? Obviously, you cannot just call it a whim, but you often feel that way - it leads to sporadic animation, among other things. So, is there any quick way to check if a form / application needs to call DoEvents?

+3
source share
3 answers

Oh spirit - I just hit myself.

I just need to use the background thread for processing and leave the user interface thread separate.

+8
source

If you don’t want to bother with streams, and you are not against a bit of beta testing, Visual Studio Async CTP might be worth a look - basically “DoEvents made the right path” (and much more).

async .

+1

Instead of messing with threads, you can use BackgroundWorker . This simplifies the execution of work and updating the controls on the form, since you cannot update the user interface control directly from a thread other than the UI. The example in the docs updates the Label control, but you can easily change it to use the ProgressBar.

+1
source

Source: https://habr.com/ru/post/1773547/


All Articles