# GUI refresh while waiting for thread to finish

**URL:** <https://forum.juce.com/t/gui-refresh-while-waiting-for-thread-to-finish/15092>\
**Category:** General JUCE discussion\
**Created:** [July 9, 2015, 11:39am UTC](https://forum.juce.com/t/gui-refresh-while-waiting-for-thread-to-finish/15092 "2015-07-09T11:39:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kroko](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kroko/32/1151_2.png) [@Kroko](https://forum.juce.com/u/Kroko)\
**Post date:** [July 9, 2015, 11:39am UTC](https://forum.juce.com/t/gui-refresh-while-waiting-for-thread-to-finish/15092/1 "2015-07-09T11:39:38Z")

</div>

How can I refresh GUI and make application responsive while I'm waiting for thread to finish?

```
while (!thread.wait(10))
{
//refresh GUI????
}
```

I found&nbsp;MessageManager::deliverAllPendingMessages but it is no longer implemented.

In C# I can do this with&nbsp;Application.DoEvents.&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [July 9, 2015, 12:34pm UTC](https://forum.juce.com/t/gui-refresh-while-waiting-for-thread-to-finish/15092/2 "2015-07-09T12:34:05Z")

</div>

Find the top-most level Component and call repaint()?

---

<div class="post-metadata">

**Author:** ![Kroko](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kroko/32/1151_2.png) [@Kroko](https://forum.juce.com/u/Kroko)\
**Post date:** [July 9, 2015, 1:45pm UTC](https://forum.juce.com/t/gui-refresh-while-waiting-for-thread-to-finish/15092/3 "2015-07-09T13:45:50Z")

</div>

This does not work. Repaint just add message to queue. Problem is that those messages are not processed if application is stucked in a loop.&nbsp;

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 9, 2015, 5:24pm UTC](https://forum.juce.com/t/gui-refresh-while-waiting-for-thread-to-finish/15092/4 "2015-07-09T17:24:44Z")

</div>

Blocking the message thread and periodically forcing it to run&nbsp;to do synchronous paining&nbsp;is an old-school technique that is very dangerous, and is actually impossible on some newer platforms like Android. Don't do it!

The way to do this kind of thing properly&nbsp;is just to do your work on a thread and send messages to your GUI to tell it to repaint when necessary.
