B4J Question How do I detect a Http_job has timed out when I use Wait For

JackKirk

Well-Known Member
Licensed User
Longtime User
I have a Http_job, the bare bones of the relevant code to execute it are:

B4X:
    Private XXX_job As Http_Job

    XXX_job.Initialize("List", Me)
    
    wrk_URI stuff here

    XXX_job.Download(wrk_URI)

    XXX_job.GetRequest.Timeout = 30 * DateTime.TicksPerSecond      'I know this is the default
    
    wrk_Authorization stuff here
 
    XXX_job.GetRequest.SetHeader("Authorization", wrk_Authorization)

    Wait For (XXX_job) JobDone (Job As Http_Job)

Occasionally this hangs on the Wait For - I am assuming it is timing out.

How do I detect this?

Thanks...
 
Last edited:

JackKirk

Well-Known Member
Licensed User
Longtime User
No. The Wait For is what is causing the HTTP request to process. Please note: all statements between xxx.Download and the Wait For for that particular job must be blocking calls. Otherwise the event queue is processed and the download event occurs and may finish before you set up your Wait For. If that occurs, your Wait For will seem to hang, since the event that it is waiting for has already happened.
OliverA - thanks that is good info - I presume by "blocking call" you mean a call that does not entail a Sleep or Wait For in its execution trail.

If that's the case then there are none between:

XXX_job.Download(wrk_URI)

-and-

Wait For ...

follow post #4 from https://www.b4x.com/android/forum/threads/okhttp-cancel-download.61239/
you'll have to do a little work to make it fit your scenario.

also, the failure to time out with ok is apparently not unknown.
ok provides 4 time out settings:
drgottjr - thanks - I will follow your suggestions up and report back in this thread - may take a while because this problem only surfaces every couple of days.

How to set the default HTTP connection timeout

Hi, I can set the HTTP connection timeout for a call with Job1.GetRequest.Timeout But I have to do this on every call. Is there a way to set the timeout globally? Thanks
www.b4x.com
www.b4x.com
TILogistic - thanks - I will follow your suggestions up and report back in this thread - may take a while because this problem only surfaces every couple of days.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Apologies for taking some time to tidy up this thread - but the problem only occurs rarely and I wanted to wait for it to happen before offering a work around - which I have placed in a new thread:

 
Last edited:
Upvote 0
Top