A ardillaprogramadora Member Licensed User Jul 5, 2017 #1 Hello, im a newbie with threading. I am using the ThreadingV1.10 library. This is my code: Code: Copy 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?
Hello, im a newbie with threading. I am using the ThreadingV1.10 library. This is my code: Code: Copy 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?
DonManfred Expert Licensed User Longtime User Jul 5, 2017 #2 In most cases you should avoid using the threading library. What exactly are you trying to archieve? Upvote 0
A ardillaprogramadora Member Licensed User Jul 5, 2017 #3 DonManfred said: In most cases you should avoid using the threading library. What exactly are you trying to archieve? Click to expand... 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: Code: Copy 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: Jul 5, 2017 Upvote 0
DonManfred said: In most cases you should avoid using the threading library. What exactly are you trying to archieve? Click to expand... 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: Code: Copy 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
DonManfred Expert Licensed User Longtime User Jul 5, 2017 #4 See this https://www.b4x.com/android/forum/threads/b4x-okhttputils2-with-wait-for.79345/#content Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jul 5, 2017 #5 This is exactly the purpose of the new Wait For keyword. Upvote 0
A ardillaprogramadora Member Licensed User Jul 5, 2017 #6 DonManfred said: See this https://www.b4x.com/android/forum/threads/b4x-okhttputils2-with-wait-for.79345/#content Click to expand... thank you so much, awesome feature Upvote 0
DonManfred said: See this https://www.b4x.com/android/forum/threads/b4x-okhttputils2-with-wait-for.79345/#content Click to expand... thank you so much, awesome feature