Hi there, what’s the preferred way of handling UI updates from other threads that doesn’t involve creating MessageManagerLock instances. Is there a general pattern for handling this scenario?
thx
Hi there, what’s the preferred way of handling UI updates from other threads that doesn’t involve creating MessageManagerLock instances. Is there a general pattern for handling this scenario?
thx
It depends on what you’re doing and whether the “other” thread is the audio thread. A simple mechanism for non-audio > main thread communication for components is using postCommandMessage()
and handleCommandMessage()
. If the other thread is the audio thread then don’t do that (as postCommandMessage()
calls new
and in any case you might risk flooding the message queue). In this case using a Timer
to check a flag (which you can set in your audio thread) works well.
thanks for reply - the other thread in this case is a MIDI thread, so I’ll look into postCommandMessage - cheers!
at what point is it valid to call postCommandMessage() and have the message delivered? messages that I send early on never get delivered…
Try using AsyncUpdater… using a Message can overload the Message queue
Simply triggerAsyncUpdate() and in handleAsyncUpdate() do a repaint().
Rail
thx this is much better. Shame it doesn’t have a message to pass, but that’s easy to implement… thx for the suggestion
Someone should write a book on this topic
MessageManager::callAsync() is pretty good - but you need to faff around with weak pointers if there’s any danger of the target object being deleted while the message is in the queue.
I tend to use this a lot:
ActionBroadcaster / ActionListener does that with a String object, if that carries enough information for you
great - thx for the info, that’ll do nicely in this case
I think (and you can check me on this) ActionBroadcaster has a lock while ASyncUpdater doesn’t (which may or may nor matter depending on what you’re doing).
Cheers,
Rail