B4J Question ResumableSub don't work

Albertino

New Member
Hi All,

ResumableSub don't work in my code in a Non-UI project.

I got this message in Logs:
...
Waiting for debugger to connect...
Program started.
Program terminated (StartMessageLoop was not called).
...
I have "StartMessageLoop" in my code so why my code don't work?


This is my code:
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    
End Sub

Sub AppStart (Args() As String)

    
    Wait For(ExtractKey2("item/1/tipo")) Complete (Result As String)
    Log ("Result=" & Result)
    
    StartMessageLoop
End Sub


Sub ExtractKey2(Dati As String) As ResumableSub
    Dim indice As Int
    Dati = Dati.Trim
    Dati = Dati.ToUpperCase
    indice = Dati.IndexOf("/")
    Dati = Dati.SubString2(0, indice)
    Return Dati
End Sub


Thank you
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
See the resumable subs tutorial: https://www.b4x.com/etp.html

The code execution will return to the parent sub when you call Wait For. This will happen before the call to StartMessageLoop.

The solution is:
B4X:
Sub AppStart (Args() As String)
    DoSomething
    StartMessageLoop
End Sub

Sub DoSomething
  Wait For(ExtractKey2("item/1/tipo")) Complete (Result As String)
    Log ("Result=" & Result)
End Sub
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
As I explained someone in this forum, I think of resumable subs with result like if I sent someone to fetch a tool that I need to continue the job I am doing.
While he doesn't return, I cannot confirm if he brought the correct tool for me to continue working...
 
Upvote 0
Top