This is our solution to manage timeout in an Http Job.
If the job doesn't run on time, the timer releases it and the app exits for j.succes = false.
If the job doesn't run on time, the timer releases it and the app exits for j.succes = false.
Job timeout:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView
Private jobPostTimer As HttpJob
Private tmrTimeout As Timer
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
End Sub
Sub Button1_Click
GetInfo
End Sub
Public Sub GetInfo As ResumableSub
Dim strUrlURI As String = "http://192.0.2.0" 'Server to test the job
jobPostTimer.Initialize("job_GetInfo", Me)
jobPostTimer.PostString(strUrlURI,"")
tmrTimeout.Initialize("tmrTimeout", 10000) ' Set timer for 10 seconds
tmrTimeout.Enabled = True
Wait For (jobPostTimer) JobDone(j As HttpJob)
tmrTimeout.Enabled = False ' Disattiva il timer se il job si completa in tempo
If j.Success Then
Log(j.GetString)
Else
Log(j.ErrorMessage)
End If
j.Release
Return j.Success
End Sub
Sub tmrTimeout_Tick
tmrTimeout.Enabled = False ' Disattiva il timer
If jobPostTimer.IsInitialized Then
jobPostTimer.Release
Log("Timeout: Job out of time.")
End If
End Sub