Android Question Threads problem - i don't understand how they work

ardillaprogramadora

Member
Licensed User
Hello, im a newbie with threading. I am using the ThreadingV1.10 library.

This is my code:

B4X:
Sub Process_Globals
    Dim hilo1 As Thread
    Dim c As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
    c = 0
    hilo1.Initialise("ThreadSub")
    hilo1.Start(Me, "ThreadSub", Null)
    Sleep(2000)
    log(c)
End Sub

Sub ThreadSub
    c = 1
End Sub


Debug shows c=0 ... is not possible to access a global from a new thread?
 

ardillaprogramadora

Member
Licensed User
In most cases you should avoid using the threading library.
What exactly are you trying to archieve?

Well my problem is as follows:

i have sub 'X' that do a lot of things including download info from a website using httjob. I handle it with JobDone sub, the problem is that my sub X continues flowing while HTTJOB is not finished so X crashes because i need the info downloaded before continuing. I tried something like this with no success:

B4X:
Sub X
....
dim j as httpjob
j.Initialize("valormonedacmc",Me)
j.Download(XXXXXXX)

do until j.success = true

loop
log("downloafinished")
....
End sub

Sub JobDone (Job As HttpJob)
select job
case "valormonedacmc"
log("action")
.....
end sub

the problem is that log("action") and log("downloadfinished") never are reached by the app. The do loop is infinite. So i think maybe i can take another approach to the problem by using threads and global vars

Sorry for my bad english, is not my mother lang
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…