# runDispatchLoop() running differently on Windows and Mac

**URL:** <https://forum.juce.com/t/rundispatchloop-running-differently-on-windows-and-mac/55422>\
**Category:** General JUCE discussion\
**Created:** [March 18, 2023, 11:49am UTC](https://forum.juce.com/t/rundispatchloop-running-differently-on-windows-and-mac/55422 "2023-03-18T11:49:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qfactor](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/qfactor/32/14921_2.png) [@Qfactor](https://forum.juce.com/u/Qfactor)\
**Post date:** [March 18, 2023, 11:49am UTC](https://forum.juce.com/t/rundispatchloop-running-differently-on-windows-and-mac/55422/1 "2023-03-18T11:49:46Z")

</div>

Hi,

I’m trying to run a plugin in a console app so I need the MessageManager to be ready when I’m scanning it.

On windows this works:

> ```
> MessageManager::getInstance()->callAsync ([&app] () {
> app.run();
> });
> MessageManager::getInstance()->runDispatchLoop();
> 
> ```

On mac, runDispatchLoop() returns immediately and callAsync is never calling app.run();

Anybody can help me understand what is happening here? Thanks!

---

<div class="post-metadata">

**Author:** ![Qfactor](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/qfactor/32/14921_2.png) [@Qfactor](https://forum.juce.com/u/Qfactor)\
**Post date:** [March 19, 2023, 4:54pm UTC](https://forum.juce.com/t/rundispatchloop-running-differently-on-windows-and-mac/55422/2 "2023-03-19T16:54:52Z")

</div>

Ok, here’s the solution. Some extra code is needed in a Mac:

> ```
> #if JUCE_MAC
> namespace juce {
> extern void initialiseNSApplication();
> }
> #endif
> 
> int main (int argc, char* argv[])
> {
> #if JUCE_MAC
> initialiseNSApplication();
> #endif
> MessageManager::getInstance()->callAsync ([&app] () {
> app.run();
> });
> MessageManager::getInstance()->runDispatchLoop();
> 
> ```

---

<div class="post-metadata">

**Author:** ![yfede](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yfede/32/506_2.png) [@yfede](https://forum.juce.com/u/yfede)\
**Post date:** [March 20, 2023, 9:20am UTC](https://forum.juce.com/t/rundispatchloop-running-differently-on-windows-and-mac/55422/3 "2023-03-20T09:20:39Z")

</div>

I may be misunderstanding the purpose of your code, but if all you need is make sure that a part of your code is called on the message thread, wait for its completion, then move along on whatever thread you already were, you could make use of [`callFunctionOnMessageThread()`](https://docs.juce.com/master/classMessageManager.html#a7dfc992326dc090f1ade02f62614bad8)
