AsyncUpdate behaviour when called in loop

I have a strange behaviour when I do this :

void AComponent::handleAsyncUpdate() {
	++_numJuceLoops;
	triggerAsyncUpdate();
}

The mouse inputs are all ignored (but not the keystrokes) making the GUI unusable. In first place I wanted to count the number of juce loops. I could use a timer with 1ms, but i’m not sure if it will count the number of loops of juce. Probably not.

I have to admit, I am not that familiar with AsyncUpdater.
But you are triggering an async update from within “handleAsyncUpdate”. I am not sure, that’s a good idea.

Yes, I understand that it could be a kind of infinite loop, and that explain why the UI is unusable, but I thought AsyncUpdater was meant to block anything, thanks to the asynchronous system supposed to let the juce event loop do the others stuffs before going back to the async event handling ^^’

That is a misunderstanding. The AsyncUpdater is not blocking anything. It is just posting a message for later use into the message queue.

It is also used in situations, that would otherwise require a MessageManagerLock, which is probably where this misunderstanding comes from.

By being executed on the message thread it is safe to call message thread only methods, such as setBounds(), repaint() etc.

Yes, this is what I understood. So why is it actually blocking the gui when I use the following code ? I mean, this is an example I tested.

void AComponent::handleAsyncUpdate() {
	++_numJuceLoops;
	triggerAsyncUpdate();
}

Probably because that ends up endlessly posting the messages into the message queue. The system eventually might not be able to handle all the messages that accumulate. (It might still handle some, though.)

At this point, someone has to ask : what are you actually trying to do?

I wanted to create a class like :

class JuceEventLoopCounter : AsyncUpdater {
public:
   JuceEventLoopCounter() : numJuceLoops(0) {}
   
   void start() {
   	triggerAsyncUpdate();
   };
   
   int64 getNumJuceLoops() const { return numJuceLoops; }
   
private:
   void handleAsyncUpdate() {
   	++numJuceLoops;
   };

   int64 numJuceLoops;
};

To measure at wich point some events were sent more precisely than with a timer.

And I thought it was possible, because in the documentation we can read Basically, one or more calls to the triggerAsyncUpdate() will result in the message thread calling handleAsyncUpdate() as soon as it can..

So asynchronous + only one call even if there is :

triggerAsyncUpdate();
triggerAsyncUpdate();

should not block anything.