Waiting for a thread


Hi all,

I’m faced with a problem in using juce. I’m starting to be OK with sound processing using juce but I still don’t master the UI and Message part of Juce. The solution is probably quite simple but I haven’t found it yet.

I have a UI component (with several buttons).
When I click on one of the button a thread start that make some processing.

At the end of this processing the thread have to warn the UI component that it has finished his job so that the ui component can use the result…

I have tried to run a while loop in the component to wait until the thread have finished. Something like :

while (!thethread->jobDone()) { wait(1000); }

but the it blocked the execution of the thread…

I have thought about using Messages but I did not really understand how it works…

In the component (derived from MessageListener) I have my handleMessage method that check if the message is the on I’m waiting for.
If it is not, Should I dispatch the received message ? if yes how ? And then How the thread can send the Message. it have be also a MessageListener and use postMessage ?

Is there a better way to achieve what I want ?

Thanks in advance juce gurus…

Tourcoing, france


Maybe ThreadWithProgressWindow will do what you need?


Not really. I looked at the code and it would have been lot of recoding to have my app work like this…

However, I have found a simple way… I just pass to my thread a pointer to a Button that is on my UI component so that the thread can trigger it when his work is done…

May be not very elegant but it works.

Thanks Jules for your fast answer. I should spend enough time through all the class provided by juce…