Hello everyone! I have to update an old project, and I have to replace the old Msgbox with the new MsgboxAsync. With this last, I have a strange behavior: after invoking the MsgboxAsync, the message appears on the display but the execution continues regardless. I think I have mistaken the management of synchrony. Here is the piece of code in question:
B4X:
Sub Activity_Create (FirstTime As Boolean)
Set_App 'I call this function
Set_Layout
'etc...
End Sub
Sub Set_App
If File.Exists("percorso","abc.de") = False Then 'First run
Dim ro As Object = Msgbox2Async("File di avvio non trovato." & CRLF & "Utilizzare il fle di default?","File mancante","SÌ","","NO",Null,False)
Wait For (ro) Msgbox_Result (res As Int)
If res = DialogResponse.POSITIVE Then
'etc
End Sub
After the execution of the line with the Wait For, the message is shown correctly on the display, but the execution continues with the Set_Layout function (as if the execution of Set_App were interrupted and continues with the next function present in the Activity_Create). Can you tell me where am I wrong? Thank you so much
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...
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...
MsgboxAsync("Internal error.","Attention")
Wait For Msgbox_Result (res0 As Int)
How can I wait for the user clicks on "ok" button? Do I have to wait, with the same logic as before, for the entire function containing the MsgboxAsync?
And... @Erel I have a BTSerialPrinter_Connected (Success as Boolean) event, in which I show a MsboxAsync in the Success=False case. How can I handle this, to wait for it?
Is this code right?
B4X:
Sub BTSerialPrinter_Connected (Success As Boolean) As ResumableSub
'etc...
Return Null
End Sub
Sub BTPrinterConnect
Wait For BTSerialPrinter.Connect(params...) Complete (Result As Object)
End Sub
MsgboxAsync("Internal error.","Attention")
Wait For Msgbox_Result (res0 As Int)
How can I wait for the user clicks on "ok" button? Do I have to wait, with the same logic as before, for the entire function containing the MsgboxAsync?
Msgbox2Async(" Do you want to do this?", "Question", "Yes", "Cancel","No" , Null, True)
Wait For msgbox_result (Result As Int)
Select Case Result
Case DialogResponse.POSITIVE
Log("Yes")
Case DialogResponse.CANCEL
Log("Cancel")
Case DialogResponse.NEGATIVE
Log("No")
End Select