thread in vb.net with winform
Private Sub btnRechercheUtilisateur_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRechercheUtilisateur.Click
Dim t As New Thread(New ThreadStart(AddressOf RunInThread))
t.Start()
End Sub
Public Delegate Sub MyDelegate(ByVal arg As Integer)
Private Sub RunInThread()
Dim delInstatnce As New MyDelegate(AddressOf RechercheUtilisateurView)
Me.BeginInvoke(delInstatnce)
imgLoading.Visible = True
'Add your code that needs to be executed in separate thread
'except UI updation
End Sub
Public Sub RechercheUtilisateurView()
'Vérifie si la session est valide
If notes.IsSessionValide = False Then
LoginPanel.Visible = True
Exit Sub
End If
'Vide la liste
lstSearchUsager.Items.Clear()
lstGroupesUsager.Items.Clear()
'Uncheck checbox
chkGroupesUsager.Checked = False
'UI Setting pour le loading
' StartLoadingImg(172, 152)
txtSearchUsager.Enabled = False
btnRechercheUtilisateur.Enabled = False
'Ajoute les éléments de la liste
Dim users As List(Of UsagerNotes) = notes.GetUsagersByKeyword(txtSearchUsager.Text)
'Vérifier si un résultat a été retourné
If users.Count <> 0 Then
Dim rows(users.Count - 1) As ListViewItem
开发者_如何学运维 Dim counter As Integer = 0
'Loop d'ajout d'utilisateur au ListView
For Each u In users
Dim row As New ListViewItem
row.Text = u.nomCanonique
row.ImageKey = "1"
rows(counter) = row
counter += 1
Next
lstSearchUsager.Items.AddRange(rows)
Else
AddEvent("Aucun résultat trouvé pour la recherche utilisateur: " + txtSearchUsager.Text, "21")
End If
txtSearchUsager.Enabled = True
btnRechercheUtilisateur.Enabled = True
End Sub
When i use the debugger, my code would freeze at around txtSearchUsager.Enabled = False Can anyone please help me, I am confused
Thanks Gibit
You must include all function calls (include change the enabled property of the textbox) in a separate function and call this function over a delegate with Me.Invoke or Me.BeginInvoke.
精彩评论