B4J Question Sub Jobdone never called

Discussion in 'B4J Questions' started by rdkartono, Apr 16, 2015.

  1. rdkartono

    rdkartono Member Licensed 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.

    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)
        parent = ParentObject
    Log("Parent Object : "&parent)
    End Sub
    Public Sub refresh_cities
    Log("Refreshing cities")
    End Sub
    Public Sub refresh_schedules(citycode As Int)
    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")
    End If
    Case "getshalat"
    If evtname<>"" Then
    Log("Calling "&evtname&"_schedulereloaded")
    End If
    End Select
    End If
    End Sub
  2. Erel

    Erel Administrator Staff Member Licensed User

    Are you calling StartMessageLoop somewhere? Otherwise the program will end before the result arrives.
  3. rdkartono

    rdkartono Member Licensed 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 ?
  4. Erel

    Erel Administrator Staff Member Licensed User

    If you are not calling StareMessageLoop in a console app then the app terminates when AppStart completes.
  5. rdkartono

    rdkartono Member Licensed 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.
  6. Erel

    Erel Administrator Staff Member Licensed User

    Does it work if you add the source code to the project instead of the compiled library?
  7. rdkartono

    rdkartono Member Licensed 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".
  8. Erel

    Erel Administrator Staff Member Licensed User

  9. Erel

    Erel Administrator Staff Member Licensed User

    I've tried it with a simple project and it worked fine.

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

    Public Sub Initialize
    Dim j As HttpJob
    "j", Me)
    End Sub

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

    The main module code:
    Sub AppStart (Form1 As Form, Args() As String)
       MainForm = Form1
    Dim c As Class1
    End Sub
  10. rdkartono

    rdkartono Member Licensed 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 ?
  11. Erel

    Erel Administrator Staff Member Licensed User

    Not sure. Try to compile it as a UI app and see whether it makes any difference.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice