Android Question Wait For not waiting for job to finish

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi,

I am using below code by Erel to calculate size of remote file and then downloading it thru FTP.(Because FTP doesnt provide Total File Size in Total Parameter)
B4X:
Sub PF_FileSize(sFileName As String) 
   
    Dim j As HttpJob
    Dim sPath As String
    Dim result As String=""
   
    sPath="http://xyz.in/App/Profile/" & sFileName
    If FileMap.IsInitialized=False Then
        FileMap.Initialize        
    End If
   
    j.Initialize("", Me)
    j.Head(sPath)
    Wait For (j) complete (j As HttpJob)
    If j.Success Then
        Dim length As List = j.Response.GetHeaders.GetDefault("content-length", Null)
        If length.IsInitialized  Then
            result=length.Get(0)
            FileMap.put(sFileName: Result)
        End If
    End If
End Sub

but the execution doesn't wait for job to finish it continues to next line which starts FTP download.

Can anyone pls give a clue what is missing here.

Thanks
Juzer
 

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
Thank You DonManfred for prompt reply.
I will try this way by calling the whole function with Wait For.
Juzer
 
Upvote 0
Top