How does CallDelegateOnMainThreadMBS work?

I am trying to get CallDelegateOnMainThreadMBS to work as CallMethodOnMainThreadMBS is now deprecated, but there are no examples for CallDelegateOnMainThreadMBS.

I want to call a Method (called doMsgOnMainThread) inside a Module (called CommonWindow), pass it a String and have it display that string. The idea is that inside a Thread I will be able to display a MsgBox later in the Main thread.

Protected Sub doMsgOnMainThread(Message As String) MsgBox Message End Sub

When I call CallDelegateOnMainThreadMBS inside the thread, no message is displayed once the thread is complete (the breakpoint inside doMsgOnMainThread is never triggered) eg

Call CallMethodOnMainThreadMBS(AddressOf commonWindow.doMsgOnMainThread, "Display this message")

Am I holding it wrong?

https://www.monkeybreadsoftware.net/process-calldelegatesmbs-method.shtml

Your code looks okay. Here is how I use the method:

CallDelegateOnMainThreadMBS AddressOf SetMailMaximum, MailMaximum

and

Private Sub SetMailboxMaximum(theMaximum as Integer) PBMailbox.Maximum = theMaximum End Sub

I’ll make an example project and send you a copy.

Fantastic. As you can see in my example I was wrongly using CallMethodOnMainThreadMBS instead of CallDelegateOnMainThreadMBS.

Christian, your example was great.