B4J Question [SOLVED] Weird return from sub issue in release mode

rosippc64a

Active Member
Licensed User
Longtime User
Hi All!
I have a non-UI app and a code, where I call an external program:
B4X:
Sub startLister2(param As String) As ResumableSub
    If File.Exists(File.DirApp,"lszamlawr.exe") Then
 ...       
        Dim shl As Shell
        shl.Initialize("shl", "lszamlawr.exe",pl)
        shl.WorkingDirectory = File.DirApp
        shl.InputStreamEnabled = True
        shl.RunWithOutputEvents(-1)
        'Wait For (shl) shl_StdOut (Buffer() As Byte, Length As Int)
        wait For (shl) shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
        Log($"$DateTime{DateTime.Now} - listgenerátor kész. Success:${Success} Exitcode:${ExitCode}"$)
    Else
        doLog("Lister2","Nem készíthető A/4-es lista, nincs meg a nyomtató modul!" & CRLF & File.dirapp)
    End If
    Return True
End Sub
The external program runs correctly, but in _RELEASE_ mode the last executed line is the 11.
After that no return in line 15 The program flow 'disappear'. No error code, no clue...
I cleaned my app: no changing. In debug mode all is ok, in release mode only the problem.
How can I reveal the reason of this disappearing?
thanks in advance
Steven
 

stevel05

Expert
Licensed User
Longtime User
How are you calling startListener2? It should be with a Wait For to maintain the correct program flow.
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
Here is the call:
B4X:
private Sub lista1(sql As SQL,in As StringBuilder) As ResumableSub
    Dim sqlstr As String
    sqlstr = $"
    select *,round(((teljes-brutto)/teljes)*100,3) as atlag,
    round(teljes/smenny,2) as listar,round(brutto/smenny,2) as szlaar from (
    select date(keltdat) as keltdat,szfej.rksh,megnevezes,me,sum(menny)as smenny,
    sum(ebruttoar*menny) as teljes,
    sum((ebruttoar-bruttoar)*menny) as engedmeny,
    sum(sorbrutto) as brutto
    from sztet
    join szfej on sztet.bsz=szfej.bsz
    where ebruttoar-bruttoar>=0 and szfej.kommid in (${in.ToString})
    group by keltdat,szfej.rksh,megnevezes,Me
    having sum(menny)<>0
    order by 2,1,3) a               
                "$
    Codebase.doLog("Email",    $"Automatikus adatküldés emailben: Cikkenkénti eladások naponta/készlethely"$)
    Dim pdfnev As String = File.Combine(File.DirTemp,"ARBEVCIKKNAP"&DateTime.GetSecond(DateTime.Now)&".pdf")
    Dim lid As Int = sql.ExecQuerySingleResult2($"
        INSERT INTO winlista (cegid,listanev,sql,filter,szerkeszt,outfname)
        VALUES (?,?,?,?,?,?) RETURNING id
        "$,Array As Object(Codebase.selceg.focegid,"ARBEVCIKKNAP",sqlstr,"komm.id=" & in.ToString, _
        "N",pdfnev))
    Log($"$DateTime{DateTime.Now} - startLister2 hívása."$)
    wait for (Codebase.startLister2($"ID=${lid}"$)) complete (res As Boolean)
    Log($"$DateTime{DateTime.Now} - startLister2 kész."$)
    Return pdfnev   
End Sub
and here is the call of lista1:
B4X:
wait for (lista1(sql,in)) complete (pdfnev As String)
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
B4X:
        wait For (shl) shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String) '<-- works'
        Log($"$DateTime{DateTime.Now} - listgenerátor kész. Success:${Success} Exitcode:${ExitCode}"$)                '<-- works
    Else
        doLog("Lister2","Nem készíthető A/4-es lista, nincs meg a nyomtató modul!" & CRLF & File.dirapp)
    End If
    Return True '<-- program flow disappear... no error, no return, nothing in release mode
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
Here is the project, but it needs postgresql database, an external exe and some fastreport format file.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I have a non-UI app and a code, where I call an external program:
It is a server app. This is the correct description as server apps have a different threading model and it is only applied in release mode.
There is at least one problem. Codebase is a static code module. This means that its events will be raised on the main thread, which means that you cannot call it directly from a handler class.

The solution in this case is simple. Use shl.RunSynchronous and don't make it a resumable sub. It is possible that there are other violations.
 
Upvote 0
Top