Hi, All.
I would like to download data from internet periodically by background thread.
With reference to:
Threading library
https://www.b4x.com/android/forum/threads/threading-library.6775/,
I changed the code as follow but get freezed
if I skip Do Until ... Loop, it seems work.
Php Code with file name: sleepfor1sec.php:
It seems that Wait For inside Thread would escape. How can make "wait for" not escape?
Program run in video:
I would like to download data from internet periodically by background thread.
With reference to:
Threading library
https://www.b4x.com/android/forum/threads/threading-library.6775/,
I changed the code as follow but get freezed
B4X:
Sub ThreadSub3
'Dim Count As Int = 0
Dim Params(1) As Object
Dim ok3 As Boolean = False
Dim trying As Int = 0
Dim Count As Int
Do While Count < 1000
Count = Count + 1
Params(0) = Count
sendPhpTimeIntent
Wait For getJobResponse(map_1 As Map)
StopService(svcPhpTime)
LogColor("Start time: " & map_1.Get("start"), Colors.Blue)
LogColor("End time: " & map_1.Get("end"), Colors.Blue)
'******************************************
'This not work and get freeze!!!
Do Until ok3
'Count = Count + 1
Params(0) = Count
' this is because Android seems to lose the run message if the user presses back button
' this way no message will be ignored
Thread3.RunOnGuiThread("Update3", Params)
ok3 = Lock3.WaitFor(1000)
If ok3 Then
LogColor("ok3's value: " & ok3 & " with trying: " & trying, Colors.Blue)
Else
LogColor("ok3's value: " & ok3 & " with trying: " & trying, Colors.Red)
End If
trying = trying + 1
Loop
Loop
End Sub
if I skip Do Until ... Loop, it seems work.
B4X:
Sub ThreadSub3
'Dim Count As Int = 0
Dim Params(1) As Object
Dim ok3 As Boolean = False
Dim trying As Int = 0
Dim Count As Int
Do While Count < 1000
Count = Count + 1
Params(0) = Count
sendPhpTimeIntent
Wait For getJobResponse(map_1 As Map)
StopService(svcPhpTime)
LogColor("Start time: " & map_1.Get("start"), Colors.Blue)
LogColor("End time: " & map_1.Get("end"), Colors.Blue)
'*****************************************
' This Work!
Thread3.RunOnGuiThread("Update3", Params)
Loop
End Sub
Php Code with file name: sleepfor1sec.php:
PHP:
<?php
// displaying time
$start = date('h:i:s');
// delaying execution of the script for 5 seconds
sleep(1);
// displaying time again
$end = date('h:i:s');
echo "{\"start\":\"" . $start . "\",\"end\":\"" . $end . "\"}";
?>
It seems that Wait For inside Thread would escape. How can make "wait for" not escape?
Program run in video:
Attachments
Last edited: