Question

I am writing an application that pulls computer names from Active Directory. The process is suh-low.

Dim childEntry As DirectoryEntry
    Dim ParentEntry As New DirectoryEntry()
    Try
        ParentEntry.Path = "WinNT:"
        For Each childEntry In ParentEntry.Children
            Dim newNode As New TreeNode(childEntry.Name)
            Select Case childEntry.SchemaClassName
                Case "Domain"
                    Dim ParentDomain As New TreeNode(childEntry.Name)
                    TreeView1.Nodes.AddRange(New TreeNode() {ParentDomain})

                    Dim SubChildEntry As DirectoryEntry
                    Dim SubParentEntry As New DirectoryEntry()
                    SubParentEntry.Path = "WinNT://" & childEntry.Name
                    For Each SubChildEntry In SubParentEntry.Children
                        Dim newNode1 As New TreeNode(SubChildEntry.Name)
                        Select Case SubChildEntry.SchemaClassName
                            Case "Computer"
                                ParentDomain.Nodes.Add(newNode1)
                        End Select
                    Next
            End Select
        Next
    Catch Excep As Exception
        MsgBox("Error While Reading Directories")

    Finally
        ParentEntry = Nothing
    End Try

So question time.

1.) Would it speed up the process by running this code in another thread?

2.) If so, how would I go about doing that? (Keep in mind, I've never pulled off multi-threading successfully)

Thanks all!!

Was it helpful?

Solution

I am not supprised in the slightest that is slow! If you look into the System.DirectoryServices.AccountManagement namespace you'll find a much simpler and faster way to get things like lists of computer names.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top