triggerAsyncUpdate and repainting


#1

If i call:

repaint(); 
triggerAsyncUpdate(); 

Will the screen repaint before the handleAsyncUpdate callback?


#2

undefined. if you want to go sure, put repaint() inside the async callback.


#3

The action during the callback is quite long sometimes … it’s some app startup stuff. Wanted to make sure the UI was updated with a ‘waiting…’ message for a second. I could move the app startup stuff to another thread, maybe, but it’s going to be a pain :slight_smile:


#4

Warning, this is a hack :wink:

repaint();
MessageManager::getInstance()->runDispatchLoopUntil(50);


#5

I.e. just pump the message loop a few times and see what happens ? :slight_smile:


#6

The use case here is quite significant. If you’re displaying a splash screen during startup and want to make sure the status message updates then you can manually pump the message loop as chkn says MessageManager::getInstance()->runDispatchLoopUntil(50);. (Another way to do this to ensure paint has actually been called in time and you don’t keep pumping away nothingn is to set a flag or counter in your paint method so you know when it has been called and hence the text updated).

Another option would be to break up your initialisation code in to several smaller functions and call repaint in between them then call each function asynchronously. Of course, you’re still not guaranteed that the repaint will happen but it’s likely if the screen hasn’t been painted for a while.

Of course the best method is to put as much as possible on to a background thread and only do what you must on the message thread. std::async can come in useful here for parallelising the loading of resources etc.


#7

Cheers dave/chkn - what i’ve done is put a switch statement in with the startup steps broken down.

void timerCallback()
{
switch (step)
{
case: startSomeShit:
  step = startTheNextShit;
break;
case: startTheNextShit:
break;
}
repaint();

}

I’m callling it on a fast timer.

I ended up putting the runDispatchLoop solution at the start of the timercallback which helped, butI think the counter in the paint method is probably more robust.


#8

My personal experience is that on Windows the WM_PAINT messages get really delayed… so repaints which work great on Mac require some additional work on Windows… so test on both platforms.

Rail