B4J Question Wait Loop or Synchronize Process

Swissmade

Well-Known Member
Licensed User
Longtime User
Hi all,

Maybe I miss something.
To Create a PDF Report with Images I need to collect the information the User have selected.
When we have a result (this can be between 1 to 800 results and Images) then I start to create the report.

Put the Information of the First record on the Page and Download the Image.
Now we get the Problem.
Download with HttpUtils2 is a ASynchronous process and I have to wait until the Image is download.
Somehow I need a waitloop and when the JobDone is trigger I can put the Image in the report and go one with the next record.
Better in this case to solve this problem, I need some Synchronous Process and not a ASynchronous process.

Somebody any idea??
 
Last edited:

Swissmade

Well-Known Member
Licensed User
Longtime User
It is never a good idea to block the main thread in a UI application. Do you have a list of images that you need to download and then do a different action?

I can create a list or Map of the Download links and then Download them. But I need this Record for record.
I have try a Timer loop but we have no possibility to Refresh something(Or I miss this too)
Problem here is, that the loop is working but when the loop is running, JobDone is not triggered.

B4X:
Sub imgTimer_Tick()
imgTimer.Enabled = False
    Dim now As Long
    now = DateTime.TimeParse(DateTime.time(DateTime.now)) + 1000
    Dim now1 As Long
    Do While now1 <= now OR HaveImage = True
        now1 = DateTime.TimeParse(DateTime.time(DateTime.now))
        'Log(HaveImage)
        If xxx.Success = True Then
            Exit
        End If
    Loop
'imgTimer.Enabled = True
End Sub
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Your loop will not work. You also don't need a timer.

What do you mean with Record for record?

I have collect the SQL Query with the Ask Result.
Then I like to put the First Record Information and the Image in the Report.
When the First Record is finish, I like to go to the next Record and do the same.
This process I like to do until all Records are in the Report.
Then I close the Report.
The User gets a nice PDF report with all Information in it they ask for.
I hope this explains more.
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Download all images and store them in a Map or List. After the last image was downloaded you should build the report.

Show an indeterminate ProgressIndicator during the download.

Nice Tip.
Only problem will be the Connection limit.
I will try.
Thanks
 
Upvote 0
Top