B4J Question Wait for... Trouble

WizardOz

Member
Licensed User
Longtime User
Hi!

I have a problem that is probably of my own design, I just dont know how to fix it.
Hope you can give me some pointers.

I have a big Sub in my program. To make it smaller I have taken parts out, but a "wait for" is giving me problems.

B4X:
Sub BIGSUB
    ...Lots of code...
    Mail(some variable, email, etc)
    ..More code...
    Mail(some variable, email, etc)
    ..even more code...
    Mail(some variable, email, etc)
End Sub

Sub MAIL(Variable,variable,variable)
    ...some code that sets up a mail using smtp...
    Wait For SMTP_MessageSent(Success As Boolean)
End sub

My problem is that not all mail is sendt. I guess its because the MAIL-sub isnt finnished before it gets called again)
Is there any way to fix this, other than duplicate the MAIL-code three times in the main BIG sub?
 

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Because you have taken the 'Wait For' out of Big Sub, you have to put one there for each call to Mail (which has to be a resumable sub).
B4X:
Sub BIGSUB
    ...Lots of code...
    Wait For (Mail(some variable, email, etc)) Complete (Success As Boolean)
    ..More code...
    Wait For (Mail(some variable, email, etc)) Complete (Success As Boolean)
    ..even more code...
    Wait For (Mail(some variable, email, etc)) Complete (Success As Boolean)
End Sub

Sub MAIL(Variable,variable,variable) As ResumableSub
    ...some code that sets up a mail using smtp...
    Wait For SMTP_MessageSent(Success As Boolean)
    Return Success
End sub
 
Last edited:
Upvote 0
Top