# Running MessageManager on non-main thread

**URL:** <https://forum.juce.com/t/running-messagemanager-on-non-main-thread/40201>\
**Category:** MacOSX and iOS\
**Created:** [June 18, 2020, 3:55pm UTC](https://forum.juce.com/t/running-messagemanager-on-non-main-thread/40201 "2020-06-18T15:55:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![polyspectralethan](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@polyspectralethan](https://forum.juce.com/u/polyspectralethan)\
**Post date:** [June 18, 2020, 3:55pm UTC](https://forum.juce.com/t/running-messagemanager-on-non-main-thread/40201/1 "2020-06-18T15:55:53Z")

</div>

I’m working on a JUCE-based shared library that is used in a larger Mac/Windows application.

For performance reasons I’d like to move the message manager thread of the library off of the application’s main thread. This works fine on Windows, but on Mac it fails immediately because the message pump is driven using NSApplication nextEventMatchingMask, which can only be called on the main thread.

Has anyone tried to solve this problem? Or does anyone with more Mac knowledge than me have any idea how hard it would be to accomplish this?

Thanks,  
Ethan

---

<div class="post-metadata">

**Author:** ![mix359](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@mix359](https://forum.juce.com/u/mix359)\
**Post date:** [August 17, 2024, 3:08pm UTC](https://forum.juce.com/t/running-messagemanager-on-non-main-thread/40201/2 "2024-08-17T15:08:01Z")

</div>

Did you find any solution to this problem?

Thanks  
Daniele

---

<div class="post-metadata">

**Author:** ![polyspectralethan](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@polyspectralethan](https://forum.juce.com/u/polyspectralethan)\
**Post date:** [August 18, 2024, 7:35pm UTC](https://forum.juce.com/t/running-messagemanager-on-non-main-thread/40201/3 "2024-08-18T19:35:15Z")

</div>

I did manage to solve/work around it somehow, but unfortunately I don’t have access to the code anymore (it was a client project), and I don’t remember the details! IIRC I had to turn off the JUCE\_MODAL\_LOOPS\_PERMITTED setting. I also had to write a bit of code at the top level of my library to dispatch messages manually rather than rely on runDispatchLoop(), so that I could handle Windows/Mac a little differently. I think a few modifications to JUCE were required to get it all working but they weren’t big.

Sorry I can’t help more – good luck!

-Ethan
