开发者

thread in vb.net with winform

I need some more help. I am a noob at threading and I am making an application on

vb.net.

Basically, what my application does is it searches in Lotus Notes for information that

I need, while it is searching for the information, i need a Gif to display some

animation. I do not want to use backgroundworker for constraint reasons. So I need to

use threads.

This is the code I have


  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜