Android Question "Wait for" question

DOM85

Active Member
Licensed User
Longtime User
Hello,

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

B4X:
Dim sf As Object = FTP.DownloadFile(DirectoryServeur & Lig, True, File.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.
 

JohnC

Expert
Licensed User
Longtime 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.
 
Upvote 0

DOM85

Active Member
Licensed User
Longtime 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:
Upvote 0

JohnC

Expert
Licensed User
Longtime 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:
Upvote 0

DOM85

Active Member
Licensed User
Longtime User
I have just done the test, in debug mode but without any breakpoint.

B4X:
Dim sf As Object = FTP.DownloadFile(DirectoryServeur & Lig, True, File.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)
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
If it says success=true but then says file not found, that is very strange and I am out of ideas.
 
Upvote 0

DOM85

Active Member
Licensed User
Longtime 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.
 
Upvote 0

DOM85

Active Member
Licensed User
Longtime 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.
 
Upvote 0

emexes

Expert
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).
B4X:
Dim sf As Object = FTP.DownloadFile(DirectoryServeur & Lig, True, File.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
 
Upvote 0
Top