Italian ci vuole un idea

ivanomonti

Expert
Licensed User
Longtime User
ciao ragazzi, ho un problema da risolvere, intanto buona sera a tutti, nell'avvio della mia app devo caricare dei setting da diverse tabelle, il problema non è poi complesso ma una volta compilato lo diventa antipatico

apro una connessione, recupero i dati, ne riapro un altra e recupero gli altri dati e cosi via fino a 5 recuperi, tutto va a scascata

esempio

recupero1 > recupero2 > recupero3 ...

il problema e che dopo la prima query e il primo risultato arrivato do via al recupero sucessivo, con il risultato di nulla, l'evento response di httpclient e morto, come se il thread avesse smesso di funzionare.

voi cosa mi consigliate.
 

picenainformatica

Active Member
Licensed User
Longtime User
Non aprire la seconda connessione dal
response della prima.
 

sirjo66

Well-Known Member
Licensed User
Longtime User
Stai utilizzando HttpUtils2 ??

Ti sei ricordato nella sub JobDone di fare un Job.Release ??

Per fare le connessioni utilizzi 5 job diversi, oppure utilizzi un solo job ??

Ci mostri un po' di codice ??

Sergio
 

ivanomonti

Expert
Licensed User
Longtime User
Sirjo ciao, no uso http classico

B4X:
Dim hc,hc1,hc2 As HttpClient

quello che ammazzava il thread del soceondo socket (hc2) era la classe toogle per il controllo wifi or 3g or airplane, ma mettendo sotto una serie di controlli e in ordine di esecuzione ho risolto il problema.

Qui metto una parte del codice (interessato) del timer che mi controlla flussi e rete

B4X:
Sub timerTl_tick

   If bCategory= False AND bPost = False AND bWiFi3g = False Then
     loadListCategory("category")
   End If

   If bCategory = True AND bPost = False AND bWiFi3g = False Then
     loadListPost("post")
   End If
   
   If bCategory = True AND bPost = True AND bWiFi3g = False Then
     tl.Initialize()
     loadGpsAndToogleWifi
     bWiFi3g = True
     ToastMessageShow("Localization enabled", True)
     AnimationButton1
   End If

   If bCategory = True AND bPost = True AND bWiFi3g = True Then
     Try
       If tl.AirplaneMode = True Then
         Button1.Enabled = False
         Ani.Stop(Button1)
         If cpn.open = True Then
           cpn.closedPanelMenu
           Dim cpn As Class_PanelMenu
         End If
         Return
       Else If tl.DataConnection = True OR tl.WiFi = True Then
         If Button1.Enabled = False Then
           Button1.Enabled = True
           Ani.Start(Button1)
         End If
         Return
       Else
         Button1.Enabled = False
         Ani.Stop(Button1)
         If cpn.open = True Then
           cpn.closedPanelMenu
           Dim cpn As Class_PanelMenu
         End If
         Return
       End If
     Catch
       Button1.Enabled = False
       Ani.Stop(Button1)
       If cpn.open = True Then
         cpn.closedPanelMenu
         Dim cpn As Class_PanelMenu
       End If
     End Try
   End If
   
End Sub

B4X:
#Region Loadcategory

Public Sub loadListCategory(Query As String)
   Dim hc1 As HttpClient
   hc1.Initialize("httpCategory")
  Dim req2 As HttpRequest
  req2.InitializePost2("http://www.xxx.com/xxx/cXVlcnlsaWJlcmE=.php?q=" & Query, "".GetBytes("UTF8"))
  hc1.Execute(req2, 1)
End Sub

Sub httpCategory_ResponseError(Reason As String, StatusCode As Int, TaskId As Int)
End Sub

Sub httpCategory_ResponseSuccess(Response As HttpResponse, TaskId As Int)
   Try
     If Response <> Null Then
       jsonParseCategory(Response.GetString("UTF8"))
       Response.Release
       ToastMessageShow("Updated category list", True)
       bCategory = True
     End If
   Catch
   
     End Try
End Sub

Private Sub jsonParseCategory(s As String)
     Dim JSON As JSONParser
     JSON.Initialize(s)
     Module_setting.ListCategory = JSON.NextArray
End Sub

#End Region

#Region load post

Public Sub loadListPost(Query As String)
   Dim hc2 As HttpClient
   hc2.Initialize("httpPost")
  Dim req3 As HttpRequest
  req3.InitializePost2("http://www.xxx.com/xxx/cXVlcnlsaWJlcmE=.php?q=" & Query, "".GetBytes("UTF8"))
  hc2.Execute(req3, 1)
End Sub

Sub httpPost_ResponseError(Reason As String, StatusCode As Int, TaskId As Int)

End Sub

Sub httpPost_ResponseSuccess(Response As HttpResponse, TaskId As Int)
   Try
     If Response <> Null Then
       jsonParsePost(Response.GetString("UTF8"))
       Response.Release
       ToastMessageShow("Updated Post list", True)
       bPost = True
     End If
   Catch
     End Try
End Sub

Private Sub jsonParsePost(s As String)
     Dim JSON As JSONParser
     JSON.Initialize(s)
     Module_setting.listPost = JSON.NextArray
End Sub

#End Region
 
Top