Getting code back on the message thread in windows


#1

I have code in various places that’s running on background threads and needs to pass data back up to the UI. I know you can use the MessageManagerLock to ensure the calling thread has exclusive access to the message loop, but I’ve run into situations where using that has caused crashes. What has worked pretty well – on OS X – has been to wrap whatever callbacks I need performed in an objective c object and use the Cocoa method performSelectorOnMainThread to run the callback like so:

[objcRunnable performSelectorOnMainThread:@selector(run)
withObject:nil
waitUntilDone:NO];

I was wondering if anyone knows whether there’s an equivalent for this on Windows.


#2

I normally use a CallbackMessage these days. Or there’s MessageManager::callFunctionOnMessageThread if you need it to block and return a value. Juce has got this stuff covered - no need to mess about with platform-specific calls!


#3

Sweet, thanks… I thought there must be something for that somewhere in juce…