B4J Question Sub Jobdone never called

rdkartono

Member
Licensed User
Longtime User
Dear all,

I created a B4J module (*.bas file) to make HTTP GET to a web and it worked perfectly.
Then I move this codes to a new project (Non UI), compiled it As Library (Alt + 5), and compilation success, no error. The new library showed up at library list.

However when i am calling this library from another project, Sub Jobdone is never called.
I confirmed using Wireshark, and this program is really GET-ing the web normally, so Jobdone SHOULD be called, but its not.

examining LOG outputs, "refreshing cities" and "refreshing schedules" are displayed, but "Jobdone Sub" is unavailable.

Please help what might wrong.

B4X:
Sub Class_Globals
    Private cityget_job As HttpJob
    Private shalat_job As HttpJob
    
    Private evtname As String=""
    Private parent As Object
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(ParentObject As Object,Eventname As String)
    Cities.Initialize
    Sholat.Initialize
    evtname=Eventname
    parent = ParentObject
    Log("Parent Object : "&parent)
   
End Sub
Public Sub refresh_cities
    Cities.Initialize
    cityget_job.Initialize("cityget",Me)
    cityget_job.Download("http://jadwalsholat.pkpu.or.id")
    Log("Refreshing cities")
End Sub
Public Sub refresh_schedules(citycode As Int)
    Sholat.Initialize
    shalat_job.Initialize("getshalat",Me)
    shalat_job.Download("http://jadwalsholat.pkpu.or.id/monthly.php?id="&citycode)
    Log("Refreshing schedules")
End Sub

Private Sub JobDone(job As HttpJob)
    Log("JobDone Sub")
    Dim citycode As Int = 1
    If job.Success Then
        Log("Job success")
        Select job.JobName
            Case "cityget"
                ........
                If evtname<>"" Then
                    Log("Calling "&evtname&"_cityreloaded")
                    CallSub2(parent,evtname&"_cityreloaded",Cities)
                End If
            Case "getshalat"
                ...........
                If evtname<>"" Then
                    Log("Calling "&evtname&"_schedulereloaded")
                    CallSub2(parent,evtname&"_schedulereloaded",Sholat)
                End If
        End Select
    End If
    job.Release
End Sub
 

rdkartono

Member
Licensed User
Longtime User
Hi Erel,

above code is from a class i created, while on MAIN module, i keep empty on appstart. Do i need to give StartMessageLoop on appstart in Main ? Or i give it on Initialize function ?
 
Upvote 0

rdkartono

Member
Licensed User
Longtime User
sorry for very late reply, was very busy Erel.

So i followed your advice like follow :
1. If i put startmessageloop at AppStart sub in Main module, compile as Library, refresh library in B4J project, the Jobdone sub still not called.
This is because Main module is always excluded when compiling as Library, right ?
2. If i put startmessageloop at Initialize sub in class, compile as library, refresh library in B4J project, then main UI program will hang.
3. If i put startmessageloop in Main UI module in B4J project and run it, B4J will error, saying startmessageloop only for Non-UI application.

So currently i still can not get JobDone sub called.

I can email you my project and my library for your examine.
 
Upvote 0

rdkartono

Member
Licensed User
Longtime User
Exactly Erel, when this code just a class behind Main UI project (instead of compiled library), these codes work perfectly !
Then i want to compile it become library for easy use in future, then discovered that Jobdone sub is never called.
And I verified using Wireshark, HTTP processes are working normally, the same between "class mode" and "library mode".
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've tried it with a simple project and it worked fine.

This is the class code:
B4X:
'Class module
Sub Class_Globals
   Private fx As JFX
End Sub

Public Sub Initialize
   Dim j As HttpJob
   j.Initialize("j", Me)
   j.Download("https://www.b4x.com")
End Sub

Sub JobDone(job As HttpJob)
   Log(job)
   job.Release
End Sub
I've created the library from an UI app and tested it from an UI app.

The main module code:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   Dim c As Class1
   c.Initialize
   MainForm.Show
End Sub
 
Upvote 0

rdkartono

Member
Licensed User
Longtime User
Hi Erel, sorry for late reply.

So your library skeleton is from UI app ? I created my library skeleton from Non_UI App.
I thought my library should be universal, so can be executed from UI apps or non-UI app (such as Raspberry Pi headless app).

Do you think that is the problem ? I should create my library skeleton from UI app ?
 
Upvote 0
Top