Android Question ANSWERED: Send file via HTTP at the end of Application_Error

Lee Gillie CCP

Active Member
Licensed User
Longtime User
I found that PostFile at the end of my starter service Application_Error event was not occurring. This must be the total end of life, even for asynch HTTP requests made. So I have been attempting to stall Application_Error from exiting UNTIL I know the HTTP job request has completed. Unfortunately the JobDone never seems to fire. So I introduced 10 seconds of DoEvents, and now the POST does successfully occur (as evidenced by the receiver). I would like to minimize the stall if possible.

I am attempting to use a Lock (ErrorPostLock) to stall final exit, but the Lock is never unlocked. The very end of my Application_Error sub looks like this...
B4X:
    ErrorPostLock.Initialize( True)
   
    Dim job As HttpJob
    job.Initialize("Crash", Me)
    job.JobName = dt & "ERR"
    job.Tag = zip

    Dim link As String = Globals.WebApiBaseUrl & "/Crash"
    Log("Sending error report link=" & link & ", fldr=" & fldr & ", zip=" & zip)
    job.PostFile(link,fldr,zip)
   
    job.GetRequest.SetContentType("application/zip")
    Log("Send requested, waiting for completion...")
    Dim waitcount As Int = 0
    Do While Not(ErrorPostLock.WaitFor(500)) And waitcount < 20
        DoEvents
        Log("waiting...")
        waitcount = waitcount + 1
    Loop
    Log("Request completed, exiting program")
    Return True       
End Sub

Also in the starter service is the JobDone....

B4X:
Public Sub JobDone(Job As HttpJob)
    Log("JobDone status for " & Job.JobName & " is " & Job.Success)
    If Job.Success = True Then
        Dim tg As String = Job.Tag
        If tg.EndsWith("ERR.zip") Then
            File.delete(File.DirRootExternal,tg)
        End If
    End If
    Job.Release
    ErrorPostLock.Unlock
End Sub

Logging reveals to me that JobDone is not ever called....

B4X:
at Main.btnTest_Click
main_btntest_click (java line: 525)
java.lang.NumberFormatException: Invalid double: "sdf"
    at java.lang.StringToReal.invalidReal(StringToReal.java:63)
    at java.lang.StringToReal.parseDouble(StringToReal.java:269)
    at dalvik.system.NativeStart.main(Native Method)
       etc......
ELJAY DELIVERY Starter.Application_Error
Sending error report link=https://EMDS.odp.com:8081/Eljay/Crash, fldr=/storage/emulated/0, zip=OKTK•—ERR.zip
Send requested, waiting for completion...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
Request completed, exiting program

Notice we never see the LOG at the first line of JobDone.
 

Lee Gillie CCP

Active Member
Licensed User
Longtime User
Makes absolute perfect sense. I just wasn't sure on the mechanics. I implemented your suggestion and all works perfectly now. I always learn much from forums. Thank you so much.
 
Upvote 0
Top