我正在开发工作程序,用户可以在广告中搜索某台计算机的资产标签。如果找到它,它将在列表框中为他们提供一个列表。我已经完成了所有这些工作,但是当他们进行搜索时,用户界面会冻结。我是 VB 和 OO 的新手。我知道它是冻结的,因为搜索在与 UI 相同的线程上运行,但我无法在我的生活中找到另一个线程来完成这项工作。当我尝试在另一个线程中进行搜索时,我无法更新列表框,因为它不在同一个线程上。任何帮助将不胜感激。
搜索广告的功能:
Private Function searchAd()
'clear the results from previous entries
' AdResultListBox.Items.Clear()
Try
Dim rootEntry As New DirectoryEntry("GC://mydomaininfo")
Dim searcher As New DirectorySearcher(rootEntry)
'selects the Computer Name property
searcher.PropertiesToLoad.Add("cn")
Dim compname As String = PropertyTagTextbox.Text
'searches using wildcards
compname = "*" + compname + "*"
searcher.Filter = "(&(name=" + compname + ")(objectcategory=moreADinformation))"
Dim results As SearchResultCollection
results = searcher.FindAll()
Dim result As SearchResult
For Each result In results
'this is the part i'm having trouble with
Me.AdResultListBox.Items.Add(result.Properties("cn")(0)
Next
Catch ex As Exception
End Try
End Function
Private Sub ADSearchButton_Click(sender As Object, e As RoutedEventArgs) Handles ADSearchButton.Click
AdResultListBox.Items.Clear()
'create the new thread for searching
Dim SearchThread As New Thread(AddressOf searchAd)
SearchThread.Start()
End Sub