How to populate TreeView from a thread?

Hi Julian!

How to safely populate (call addSubItem) a TreeView component from a thread? MessageManagerLock seems doesn’t work flawlessly. Another way?

That is a bit tricky, because it’ll call repaint and various component routines. The safest way would be to post a message containing the item and have a message handler that adds it when it arrives.

What’s going wrong with the message manager lock, though? I’d have expected that to work ok.

Thank you Julian. I’ll give it a try.

the problem is when I start my program it exists right away with -1 return value (juceassertfalse in the internalRepaint function (in the Component class)). I need to restart my app sequentially several times prior to it starts normally. It’s not acceptable for me.

Strange - if you’ve used a MessageManagerLock then the assertion shouldn’t get called. Are you sure you’re not calling repaint from outside the lock?

I’ve had trouble with MessageManagerLock and stopping threads.

I’d implement a MessageListener and post messages to it from the thread. Or, use callFunctionOnMessageThread.

Matt

Yes, I’m sure! It seems that MessageManagerLock locks the massage queue in the middle of the painting operation. Although, I might be wrong.

[quote=“matt”]I’ve had trouble with MessageManagerLock and stopping threads.

I’d implement a MessageListener and post messages to it from the thread. Or, use callFunctionOnMessageThread.

Matt[/quote]
Thank you matt very much! I’ll give it a try too. :wink: