Android Question Sub JobDone is not calling

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi Erel,

I am facing strange issues as reported by others too with procedure SubJobDone.It never fires on first attempt.On second(or third etc) click it calls but I loose global values in other forms.If i put breakpoint inside SubJobDone it sometimes stops but most of the time does not.I am using rapid debugger.I have tried to search forum but could not get sure shot answer.can you pls help.Below is my code.

Job_GetUser.Initialize("Job_GetUser",Me)
Job_GetUser.Download2(ServerURL2,Array As String("Query","Select * from xxx Where UserID='" & txtID.text & "' and pwd='" & txtPassword.text & "'"))

Sub Jobdone (Job As HttpJob)
If Job.Success=True Then
Select Job.JobName
Case "Job_GetUser"
Dim parser As JSONParser
Dim response As String
response=Job_GetUser.GetString
............etc
 
Are you sure the sub is NOT called?
Maybe it is just that the Job.Success is false and so it wont run through your code

Upload a small project which shows the problem.
 
Upvote 0
Hi DonManfred,

Thanks for replying.
Below is my code.
I am assigning value to global variable in JobDone.

Sub btnLogin_Click
Job_GetUser.Initialize("Job_GetUser",Me)
Job_GetUser.Download2(ServerURL,Array As String("Query","Select Cmpycode from AppUsers Where UserID='" & txtID.text & "' and pwd='" & txtPassword.text & "'"))
If gsCmpyCode<>"" Then >>>>>>>>>>>>>>>>>>>>>>>>>break point here
---------------------------------------
Sub Jobdone (Job As HttpJob)
If Job.Success=True Then
Select Job.JobName
Case "Job_GetUser"
Dim parser As JSONParser
Dim response As String
response=Job_GetUser.GetString

If response.Length<10 Then
ToastMessageShow("Error: Incorrect User Name/ Password" & Job.ErrorMessage, True)
End If

parser.Initialize(response)
Dim rows As List
rows=parser.NextArray
Dim m As Map
Dim i As Int
i=0
m=rows.Get(i)
gsCmpyCode=m.Get("Cmpycode")
gsUserID=txtID.text
If I put breakpoint on If gsCmpyCode<>"" Then it gives me value 1 out of 3 times.I have no clue where is the problem.
Pls guide me.
Thanks
Juzer
 
Upvote 0
Sub btnLogin_Click
Job_GetUser.Initialize("Job_GetUser",Me)
Job_GetUser.Download2(ServerURL,Array As String("Query","Select Cmpycode from AppUsers Where UserID='" & txtID.text & "' and pwd='" & txtPassword.text & "'"))
If gsCmpyCode<>"" Then >>>>>>>>>>>>>>>>>>>>>>>>>break point here


You can not pretend that gsCmpyCode has changed its value here, immediately after Job_GetUser.Download2; it changes in your jobdone routine
 
Upvote 0
After some digging i got the exact problem. Actually
After Job_GetUser.Download2(ServerURL,............... I am checking the value of gsCmpyCode immediately.
This statement should execute after JobDone Routine (where gsCmpyCode is assigned value).It gets executed before that and as such it is blank.
Pls see same problem reported below.
https://www.b4x.com/android/forum/threads/how-to-wait-httpjob-execution.50313/

Can u guide me what to do.
 
Upvote 0
you could use a do while gsCmpyCode<>"" loop but that's bad design and might make your app non-responding.

your program workflow is not what it should be.
 
Upvote 0
Shall I put some delay loop. I tried checking Job_GetUser.Complete but no luck.
No it is not gold practice to hold the main thread in a delay loop. It wouldn't work anyway because the loop would prevent other events from occurring.
You have a couple of simple options....
1. Move the code following the download request into the job.Done routine, it will then run through this code if the download was successful. If unsuccessful you can choose to so something else.
2. Start a timer and on each tick event check to see if the value of gsCmpyCode has changed. You could count the number of tick events and abort if too many have occurred i.e. timeout.​

Always try and use events rather than loops!
 
Upvote 0
Thank You "RandomCoder" for elaborate help.
I moved the code into JobDone and its working fine.

Thank you guys sorex and LucaMs for replying.
 
Upvote 0
Back
Top