asyncUpdater example


#1

Hi,

is there anywhere I can find an example of how to run a function asynchronously? I need to update a message being displayed on the screen while some processes are running but I cannot find any example anywhere.

Thanks in advance


#2

You could simply use the static function MessageManager::callAsync with a lambda, but you have to be very careful that the involved objects do not get destroyed before the lambda gets a chance to get executed.


#3
MessageManager::callAsync([&]()
{
     message.set("Writing file...");

     repaint();
});

Something like this?
It gets executed at the end of the calling function anyway


#4

Well, it obviously doesn’t help if your processing/calculations happen in the GUI thread…(There really isn’t any clean and easy solution for that. You will have to change your processing to happen in another thread to be able to get GUI updates.)


#5

Have a look at ThreadPoolJob or TimeSliceThread to do the work in the background.

HTH


#6

Ok, thanks!


#7

I wanted to link a great talk at the last JUCE meetup about that topic about 2 weeks ago, but googling to Dave Rowland… too many country songs on youtube :wink:


#8

You can find the video to that talk here… https://skillsmatter.com/skillscasts/11632-audio-developers-meet-up-april

and the corresponding repo here… https://github.com/drowaudio/presentations/tree/master/Audio%20Developer%20Meetup%20April%202018