Components and MessageManagerLock


#1

Hi,

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?

Ideas?


#2

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 https://www.juce.com/doc/tutorial_handling_midi_events for an example). Or you could use a queue as you suggest. It all depends precisely what you’re doing.


#3

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


#4

Thanks for the replies!


#5

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