Remember that that a call to Sleep or Wait For in a resumable sub causes the code flow to return to the parent. Example: Sub Button1_Click Sum(1, 2) Log("after sum") End Sub Sub Sum(a As Int, b As Int) Sleep(100) 'this will cause the code flow to return to the parent Log(a + b) End Sub...
As DonManfred said, mqttclient_MessageArrived is an eventsub, you need not to wait for it, when message arrived, it will been called. the example has been explained very clear
Oh sorry, After analysing the situation, the inline wait for code is working fine, why my code not worked? because wait for line will be waiting for any publish occurred.
Where is my mistake? I was want to put publish and wait for in same code block.
I tested it by running other publish code, the wait for inline code fired normally.