多线程&活动目录

时间:2014-05-08 13:33:59

标签: vb.net multithreading active-directory

我正在编写一个从Active Directory中提取计算机名称的应用程序。这个过程非常低迷。

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

所以提问时间。

1。)是否会通过在另一个线程中运行此代码来加快进程?

2。)如果是这样,我该怎么做呢? (请记住,我从未成功完成多线程)

谢谢大家!!

1 个答案:

答案 0 :(得分:0)

我一点也不感到惊讶!如果您查看System.DirectoryServices.AccountManagement命名空间,您将找到一种更简单,更快捷的方法来获取计算机名称列表。