Android Question "Wait for" question

Discussion in 'Android Questions' started by DOM85, Jul 12, 2019.

  1. DOM85

    DOM85 Active Member Licensed User

    Hello,

    Before coming here for help i spent much time with many experiences, but with no success.
    My code is : (shorted) :

    Code:
    Dim sf As Object = FTP.DownloadFile(DirectoryServeur & Lig, TrueFile.DirRootExternal, DirectoryLocalePhotos & Lig)
    Wait For (sf) FTP_DownloadCompleted (ServerPath As String, Success As Boolean)

    do while Success = false
       sleep(
    0)
    loop

    ImagePhoto.Bitmap = 
    LoadBitmap(File.DirRootExternal,DirectoryLocalePhotos & Lig)
    In this exemple, sleep(0) allows any events to be executed.
    But the hand never come back to the do-while loop and the next "Loadbitmap" is never executed.
    I inspected in my app the only one sub event that could disturb (GPS), and i see nothing explaining the problem.
    Maybe i have bad understood somewhat.

    Thank you for your help.
     
  2. agraham

    agraham Expert Licensed User

    You don't need the loop. Wait For will resume the Sub once the DownLoadCompleted event fires. It looks like it doesn't if the loop is never reached.
     
    Erel and BillMeyer like this.
  3. JohnC

    JohnC Well-Known Member Licensed User

    Hi,

    The "Wait For" line will pause your app until the FTP action is completed, and the Success value will indicate if the action was successful or not.

    So, you should not then have a "Do While" because your app will hang if the FTP operation fails (Sucess = False) because when execution hits the Do While code, the FTP action has already finsihed, so the Success value will never change at that point.
     
  4. DOM85

    DOM85 Active Member Licensed User

    Yes, but when i don't put the loop, the "Loadbitmap" statement fails with "File not found"message. However, when i execute it step by step in Debug mode, giving the time to FTPDownload to be completed, the Loadbitmap is well executed.

    I don't see what to do.
     
    Last edited: Jul 12, 2019
  5. JohnC

    JohnC Well-Known Member Licensed User

    If you get the "File not found" error message, then that would probably indicate that success was "false".

    Replace the do..loop code with Log("Success=" & Success) and see what it reports.

    If Success reports "False" then the FTP download operation was unsuccessful for some reason and the "Wait For" is suppose to wait for the operation to complete (even if it wasn't able to download the file where success=false), so stepping through the code should not produce any different result.
     
    Last edited: Jul 12, 2019
  6. DOM85

    DOM85 Active Member Licensed User

    I have just done the test, in debug mode but without any breakpoint.

    Code:
    Dim sf As Object = FTP.DownloadFile(DirectoryServeur & Lig, TrueFile.DirRootExternal, DirectoryLocalePhotos & Lig)
    Wait For (sf) FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
    Log("Success=" & Success)  ' Answer obtained is "Success"
    ImagePhoto.Bitmap = LoadBitmap(File.DirRootExternal,DirectoryLocalePhotos & Lig)  ' "File not found error"
    I obtained the log "Success = true", and the error on Loadbitmap (file not found), and the debugger crashed (disappeared, as usual)
     
  7. JohnC

    JohnC Well-Known Member Licensed User

    If it says success=true but then says file not found, that is very strange and I am out of ideas.
     
    emexes and DOM85 like this.
  8. DOM85

    DOM85 Active Member Licensed User

    Thank you for your nice try.

    I see no solution.
    Maybe i will have to obtain the size of the image file from the server, and then to verify if the size of the file loaded is full.
    But i don't know more how to do that...

    Is it only a B4A V8.50 problem ? Erel could say it?

    Thanks again.
     
  9. agraham

    agraham Expert Licensed User

  10. DOM85

    DOM85 Active Member Licensed User

    I have not set any permission.
    But the Loadbitmap works well with small size images (300K), and fails with bigger images (>1MB).
    As the log statement displays always "success" even when the Loadbitmap crashes, maybe it is only a "Loadbitmap" problem (in my configuration).

    I don't know, but my app is not usable.
     
  11. emexes

    emexes Well-Known Member Licensed User

    Try putting a Sleep(20) in between the Wait For and the Loadbitmap. And get rid of that loop (if you haven't already).
    Code:
    Dim sf As Object = FTP.DownloadFile(DirectoryServeur & Lig, TrueFile.DirRootExternal, DirectoryLocalePhotos & Lig)
    Wait For (sf) FTP_DownloadCompleted (ServerPath As String, Success As Boolean)

    Log("DownloadCompleted: ServerPath = " & ServerPath & ", Success = " & Success)

    'do while Success = false
    '   sleep(0)
    'loop

    Sleep(
    20)    'might fix problem - if it does, get back to me and we'll try work out why (programming is art... sometimes a black art ;-)

    If Success Then
        ImagePhoto.Bitmap = 
    LoadBitmap(File.DirRootExternal,DirectoryLocalePhotos & Lig)
    Else
        
    Log("Download failed")
    End If
     
  12. emexes

    emexes Well-Known Member Licensed User

    Any success since yesterday? I'm interested to know if adding that Sleep(20) made any difference.
     
    Shelby likes this.
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