Message loop waiting for thread


#1

How can I force main message thread to process messages? 

 

I need to wait in my main thread until another thread is finished but keep processing messages. In C# and in Delphi this is simple task.

How to do this in JUCE? 

while (thread.waitForThreadToExit(100))
{
  //process messages here to avoid freeze
  //.NET - Application.DoEvents()
  //Delphi - Application.ProcessMessages();
  //JUCE - ?????
}

#2

Maybe there's a way without waiting at all? What are you trying to do?

However - http://www.juce.com/doc/classMessageManager might help though.  Maybe runDispatchLoopUntil(...)


#3

Yes, you can call runDispatchLoopUntil().

But you should NEVER do this!

Modal loops are a terrible idea from computing's past, and are impossible on modern OSes like Android, where this method won't exist. You may think it sounds like a handy thing to do, but you're almost certainly wrong, and should be looking for other non-blocking ways to do whatever it is that you're trying to achieve.

(Particularly if you're writing a plugin, this is an absolute no-go area, you'll really get into trouble if you use it)


#4

Thank you for advice. I will use CallbackMessage and state machine instead. It is more complicated but I guess in the end it will be better. 

 

 


#5

A wise choice :)