Send message to the Main Thread?

Feel like I’m asking a lot of stupid questions right now, but hopefully I’ll be able to contribute to the docs a bit after all of this! How do you send a message from a thread back to the main thread to do something like update the UI?

I’ve seen the ports and the like for passing data, but not sure how you actually get the parent (main) thread ID. Then I found be_app_messenger and assumed using SendMessage() on that would dispatch to the main looper but that doesn’t appear to be the case. Am I just using that wrong or barking up the wrong tree entirely (trying to avoid blocking the main thread while making a network request in response to user input).

I think you can just use be_app->PostMessage?

1 Like

Yeah.. I was being dumb and thinking the message handler in my main window was the one for the application.

Realised after you said that, doing this worked:

be_app->WindowAt(0)->PosMessage(_MESSAGE);

Now I’ve given my Application class it’s own MessageReceived, and pass some onto the window directly, so I can just do either be_app->PostMessage() or be_app_messenger->SendMessage(). Thanks again mate!