# How does CallDelegateOnMainThreadMBS work?

**URL:** <https://forum.xojo.com/t/how-does-calldelegateonmainthreadmbs-work/49479>\
**Category:** Extras\
**Created:** [July 24, 2019, 12:14pm UTC](https://forum.xojo.com/t/how-does-calldelegateonmainthreadmbs-work/49479 "2019-07-24T12:14:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [July 24, 2019, 12:14pm UTC](https://forum.xojo.com/t/how-does-calldelegateonmainthreadmbs-work/49479/1 "2019-07-24T12:14:36Z")

</div>

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

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

Am I holding it wrong?

[https://www.monkeybreadsoftware.net/process-calldelegatesmbs-method.shtml](https://www.monkeybreadsoftware.net/process-calldelegatesmbs-method.shtml)

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [July 24, 2019, 1:40pm UTC](https://forum.xojo.com/t/how-does-calldelegateonmainthreadmbs-work/49479/2 "2019-07-24T13:40:30Z")

</div>

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

```auto
CallDelegateOnMainThreadMBS AddressOf SetMailMaximum, MailMaximum
```

and

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

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [July 24, 2019, 2:32pm UTC](https://forum.xojo.com/t/how-does-calldelegateonmainthreadmbs-work/49479/3 "2019-07-24T14:32:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [July 24, 2019, 4:18pm UTC](https://forum.xojo.com/t/how-does-calldelegateonmainthreadmbs-work/49479/4 "2019-07-24T16:18:20Z")

</div>

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

Christian, your example was great.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [April 29, 2021, 4:01pm UTC](https://forum.xojo.com/t/how-does-calldelegateonmainthreadmbs-work/49479/5 "2021-04-29T16:01:19Z")

</div>


