J
John Wright
I have a background worker thread that scans the network listing computers
that are connected. I have a delegate that I call that invokes a procdure
that loads a dataset with computer names and then attaches it to a dropdown.
When I run it, my UI freezes until it completes. Any thoughts on how to do
this without freezing the UI?
John
Code
'General Declaration
Private Delegate Sub LoadComputerDelegate()
'called from form load
bgLoadComputers.RunWorkerAsync()
'sub that does the work
Private Sub bgLoadComputers_DoWork(ByVal sender As System.Object, ByVal e As
System.ComponentModel.DoWorkEventArgs) Handles bgLoadComputers.DoWork
tsStatus.Text = "Loading Computers. Please wait..."
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2))
Invoke(New LoadComputerDelegate(AddressOf LoadComputerDropDown))
End Sub
Private Sub LoadComputerDropDown()
'get the computers on the domain
Try
Dim enTry As DirectoryEntry = New DirectoryEntry(LDAP://[MYDOMAIN])
Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)
mySearcher.Filter = ("(objectClass=Computer)")
Dim resEnt As SearchResult
For Each resEnt In mySearcher.FindAll
Try
Dim tmpID As String = Mid(resEnt.GetDirectoryEntry.Name.ToString, 4)
If Mid(tmpID, 1, 2) = "L1" Then
Dim rwComputer As DataRow
rwComputer = dtComputers.NewRow
rwComputer("Computer Name") =
(Mid((resEnt.GetDirectoryEntry().Name.ToString), 4))
dtComputers.Rows.Add(rwComputer)
End If
tsStatus.Text = "Computers Loaded..."
cboDomainComuters.DataSource = dtComputers
cboDomainComuters.DisplayMember = "Computer Name"
Catch ex As Exception
End Try
Next
Catch ex As Exception
End Try
End Sub
that are connected. I have a delegate that I call that invokes a procdure
that loads a dataset with computer names and then attaches it to a dropdown.
When I run it, my UI freezes until it completes. Any thoughts on how to do
this without freezing the UI?
John
Code
'General Declaration
Private Delegate Sub LoadComputerDelegate()
'called from form load
bgLoadComputers.RunWorkerAsync()
'sub that does the work
Private Sub bgLoadComputers_DoWork(ByVal sender As System.Object, ByVal e As
System.ComponentModel.DoWorkEventArgs) Handles bgLoadComputers.DoWork
tsStatus.Text = "Loading Computers. Please wait..."
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2))
Invoke(New LoadComputerDelegate(AddressOf LoadComputerDropDown))
End Sub
Private Sub LoadComputerDropDown()
'get the computers on the domain
Try
Dim enTry As DirectoryEntry = New DirectoryEntry(LDAP://[MYDOMAIN])
Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)
mySearcher.Filter = ("(objectClass=Computer)")
Dim resEnt As SearchResult
For Each resEnt In mySearcher.FindAll
Try
Dim tmpID As String = Mid(resEnt.GetDirectoryEntry.Name.ToString, 4)
If Mid(tmpID, 1, 2) = "L1" Then
Dim rwComputer As DataRow
rwComputer = dtComputers.NewRow
rwComputer("Computer Name") =
(Mid((resEnt.GetDirectoryEntry().Name.ToString), 4))
dtComputers.Rows.Add(rwComputer)
End If
tsStatus.Text = "Computers Loaded..."
cboDomainComuters.DataSource = dtComputers
cboDomainComuters.DisplayMember = "Computer Name"
Catch ex As Exception
End Try
Next
Catch ex As Exception
End Try
End Sub