Components and MessageManagerLock


I have a textbox component that is a DocumentWindow. I have a separate thread that I would like to enable to send strings to this component and have it display them.

The component works, except of course that another thread can’t update it without causing threading issues. I tried MessageManagerLock but that sometimes gets stuck.

How can I safely do this? Is it possible to use a thread-safe queue of strings and have the component check that queue and pull the data from it?


You could either have a Timer that checks in the timerCallback() if the string has changed, or you could post a message from another thread and display the string in the message callback (see for an example). Or you could use a queue as you suggest. It all depends precisely what you’re doing.

If you only want to send strings ActionListener/ActionBroadcaster should work.

Thanks for the replies!

MessageManager::callAsync is also very nice for doing something like this. (Requires a new Juce version and C++11 though…)