Android Question [Solved] Job with wait for into a class

Discussion in 'Android Questions' started by ALBRECHT, Aug 11, 2019.

  1. ALBRECHT

    ALBRECHT Active Member Licensed User

    Hello,

    I have a lot of sub routines that execute some poststrings actions with an ASP API.

    So i have put the whole in a separate Code Module , like for example sending email directly via the API (its more simpler and lighter for the app) :

    Code:
    Sub SendAnEmail(QSTT As String, QSMESS As String, QSNAME As String, QSMAIL As String, QSFOOT As String, QSSUBJ As String)
        
    Dim jobsm As HttpJob
        
    Dim Params As String
        Params = 
    "QSTT=" & QSTT & "&QSMESS=" & QSMESS & "&QSNAME=" & QSNAME & "&QSMAIL=" & QSMAIL & "&QSFOOT=" & QSFOOT & "&QSSUBJ=" & QSSUBJ
        jobsm.Initialize(
    "SendEmail",Main)
        jobsm.PostString(Main.BoWebSite & 
    "/Asp/SendMail.asp", Params)
    '    Wait For (jobsm) JobDone(jobsm As HttpJob)
        If jobsm.Success Then
            
    Log(jobsm.GetString)
        
    End If
        jobsm.Release
    End Sub
    But, in that case, as i can't use a "wait for" in a static module ( to receive the return event )

    i have to check directly the success value.

    will i receive a prospective different behavior (without the "wait for" line ) of my app when i use that simple routine ?

    Regards
    Michel
     
  2. DonManfred

    DonManfred Expert Licensed User

    Do NOT use httpjobs in Code modules. Code modules can not receive any Events.
    Use a Class, a Activity or a Service.
     
    José J. Aguilar and Erel like this.
  3. ALBRECHT

    ALBRECHT Active Member Licensed User

    Ok thanks : into a class, it works great, and the mail is sending,
    but no way to log the result on the 2 last lines :
    Code:
    Log(jobsm.GetString)
        
    Return result

    Calling by Main :
    Code:
    Dim SDM As SDMail
    Dim resSDMail As ResumableSub
    SDM.Initialize(
    "ATITLE...""THEMESSAGE ...", dbmap.get("AppUserName"), dbmap.get("AppUserMail"), "TheFooter""Confirmation User Account")
    resSDMail = SDM.SendAnEmail
    SDMail class :
    Code:
    Sub Class_Globals
        
    Private QSTT, QSMESS, QSNAME, QSMAIL, QSFOOT, QSSUBJ As String
    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize (aQSTT As String, aQSMESS As String, aQSNAME As String, aQSMAIL As String, aQSFOOT As String, aQSSUBJ As String)
        QSTT = aQSTT
        QSMESS = aQSMESS
        QSNAME = aQSNAME
        QSMAIL = aQSMAIL
        QSFOOT = aQSFOOT
        QSSUBJ = aQSSUBJ
    End Sub

    Public Sub SendAnEmail As ResumableSub
        
    Dim jobsm As HttpJob
        
    Dim Params As String
        
    Dim result As String
        Params = 
    "QSTT=" & QSTT & "&QSMESS=" & QSMESS & "&QSNAME=" & QSNAME & "&QSMAIL=" & QSMAIL & "&QSFOOT=" & QSFOOT & "&QSSUBJ=" & QSSUBJ
        
    Log(Params)'**** the log appears
        
        jobsm.Initialize(
    "SendEmail","")
        jobsm.PostString(Main.BoWebSite & 
    "/Asp/SendMail.asp", Params)
        
    Wait For (jobsm) JobDone(jobsm As HttpJob)
        
    If jobsm.Success Then
            result = 
    "Success" & jobsm.GetString
        
    Else
            result = 
    "unsuccess"
        
    End If
        
        
    Log(jobsm.GetString) '**** no log appears
        Return result
    End Sub
     
  4. RJB

    RJB Active Member Licensed User

    call a sub in Main to do it?
     
  5. ALBRECHT

    ALBRECHT Active Member Licensed User

    but that's not the goal
     
  6. RJB

    RJB Active Member Licensed User

    Sorry, what is the goal? I thought you said: "but no way to log the result". I thought you wanted to log the result?
     
  7. ALBRECHT

    ALBRECHT Active Member Licensed User

    because, as i said at the first post, I have a lot of sub routines that execute some poststrings actions with an ASP API.

    So i have put the whole in a separate Code Module and now into a class (suggested by DonManFred) => and not into the main because of code organisation ...

    So i have to get a return after the call :

    Code:
    Dim SDM As SDMail
    Dim resSDMail As ResumableSub
    SDM.Initialize(
    "ATITLE...""THEMESSAGE ...", dbmap.get("AppUserName"), dbmap.get("AppUserMail"), "TheFooter""Confirmation User Account")
    resSDMail = SDM.SendAnEmail
     
  8. ALBRECHT

    ALBRECHT Active Member Licensed User

    In fact it's like saying : how to recover the value of a resumableSub not from a Main Sub but from a Class ?

    call : but no return value?
    Code:
    Dim SDM As SDMail
    Dim resSDMail As ResumableSub
    SDM.Initialize(
    "ATITLE...""THEMESSAGE ...", dbmap.get("AppUserName"), dbmap.get("AppUserMail"), "TheFooter""Confirmation User Account")
    resSDMail = SDM.SendAnEmail
    Class :
    Code:
    Sub Class_Globals
        
    Private QSTT, QSMESS, QSNAME, QSMAIL, QSFOOT, QSSUBJ As String
    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize (aQSTT As String, aQSMESS As String, aQSNAME As String, aQSMAIL As String, aQSFOOT As String, aQSSUBJ As String)
        QSTT = aQSTT
        QSMESS = aQSMESS
        QSNAME = aQSNAME
        QSMAIL = aQSMAIL
        QSFOOT = aQSFOOT
        QSSUBJ = aQSSUBJ
    End Sub

    Public Sub SendAnEmail As ResumableSub
        
    Dim jobsm As HttpJob
        
    Dim Params As String
        
    'Dim result As String
        Params = "QSTT=" & QSTT & "&QSMESS=" & QSMESS & "&QSNAME=" & QSNAME & "&QSMAIL=" & QSMAIL & "&QSFOOT=" & QSFOOT & "&QSSUBJ=" & QSSUBJ
        
    Log(Params)
        
        jobsm.Initialize(
    "SendEmail","")
        jobsm.PostString(Main.BoWebSite & 
    "/Asp/SendMail.asp", Params)
        
    Wait For (jobsm) JobDone(jobsm As HttpJob)
        
    If jobsm.Success Then
            
    Return jobsm.GetString
        
    Else
            
    Return jobsm.GetString
        
    End If
    End Sub
     
  9. Erel

    Erel Administrator Staff Member Licensed User

  10. ALBRECHT

    ALBRECHT Active Member Licensed User

    In fact, i did not think i have to make 2 "wait for" on both sides

    it works fine now with :

    1/ Adding a first 'wait for' at the call into the Main :
    Code:
    Dim SDM As SDMail
    SDM.Initialize(
    "eMailTitle","LongHtmlMessage""ToName""MailAdress", LongFooter, LongSubject)
    Wait For (SDM.SendAnEmail) complete(resSDMail As String)
    Log(resSDMail) 'Works Now
    2/ Into the class : Put the return into a string and add Job.release at the and :
    Code:
    Public Sub SendAnEmail As ResumableSub
        
    Dim jobsm As HttpJob
        
    Dim Params As String = "...." ' Post Charge
        Dim data As String

        jobsm.Initialize(
    "SendEmail",Me)
        jobsm.PostString(Main.BoWebSite & 
    "/Asp/SendMail.asp", Params)
        
    Wait For (jobsm) JobDone(jobsm As HttpJob)
        data = jobsm.GetString
        jobsm.release
        
    Return data
    End Sub
    Perfect, so i could have all my classes (with resumable sub ) sending and return values
     
    Last edited: Aug 12, 2019
Loading...
  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