Italian [risolto] B4J - thread

ivanomonti

Expert
Licensed User
Longtime User
CIAO RAGAZZI E BUON GIORNO, oggi vorrei chiedere una mano su come scrivere un for con dentro dei thread che mi mette un pochetto in gtazione in quanto ho sempre avuto problemi nel gestirli, chi li usa e mi da delle indicazioni ne sarei grato.
 
I thread sono sconsigliati (dallo stesso Erel); all'interno di ciclo poi... boh!
Cosa devi fare?

lo scenario e complesso devo leggere una tabella e creare un contexmenu per ogni object (valori diversi) uso una select con were id=?
 
Ma non vorrei che tu ti stessi impiccando per fare qualcosa di relativamente semplice, ovvero non vorrei che tu stessi creando gli oggetti (le tue etichette, pannelli o quello che sono) da codice; stai creando, invece (cosa giusta) delle custom view?

infatti è cosi ma i menu sono per ognuno diversi
 
Code: Copy
For i = 1 To 10
    'non usare WaitFor qui
    simulatedThread(sql, $"${i}"$)    
Next

Code: Copy
'filo simulato
Sub simulatedThread(db As SQL, id As String)
    Dim SenderFilter As Object = db.ExecQueryAsync("SQL", "SELECT menuName FROM menu WHERE id = ?", id)
    Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
    If Success Then
        Dim i As Int
        Do While rs.NextRow
            i = i + 1
            'risultati trovati
            Log($"Result for #${i} for ${id} = ${rs.GetString(0)}"$)
        Loop
        If i = 0 Then
            'nessun risultato trovato 
            Log($"No results found for ${id}"$)
        End If
        rs.Close
    Else
        Log(LastException)
    End If
End Sub
 
@OliverA thanks for this suggestion goes that it is a bomb and not only to drastically reduce times to a tenth without affecting the loading of records, one mistake, here he was expecting a list, corrected and goes to the wonder.

db.ExecQueryAsync("SQL", "SELECT menuName FROM menu WHERE id = ?", id) new
db.ExecQueryAsync("SQL", "SELECT fullnameassociates FROM associates WHERE idmaster = '" & id &"'", Null)

thank you, thank you, thank you 1000 :-)
 
db.ExecQueryAsync("SQL", "SELECT fullnameassociates FROM associates WHERE idmaster = '" & id &"'", Null)

Errore mio! Migliore soluzione di seguito. In questo modo si evitano problemi di iniezione SQL.

Code: Copy
db.ExecQueryAsync("SQL", "SELECT menuName FROM menu WHERE id = ?", Array As Object (id))
 
Back
Top