使用c#将映像上载到Active Directory

时间:2014-04-29 07:39:46

标签: c# vb.net active-directory

我正在使用这部分代码使用C#将图像上传到AD,工作正常。但是line directoryObject.Properties(“thumbnailPhoto”)。Clear()需要更长的时间才能减少该命令所用的时间?

           Using directory As New DirectoryEntry(address)
            Using searcher As New DirectorySearcher(directory)

                searcher.PropertiesToLoad.Add("thumbnailPhoto")
                searcher.Filter = "cn=" & targetUser

                Dim domainUser As SearchResult = searcher.FindOne()

                Using directoryObject As DirectoryEntry = domainUser.GetDirectoryEntry()
                    directoryObject.Properties("thumbnailPhoto").Clear()
                    directoryObject.Properties("thumbnailPhoto").Add(imgToByteArray)
                    directoryObject.CommitChanges()
                    Return True
                End Using

            End Using
        End Using

1 个答案:

答案 0 :(得分:0)

您可以使用任务工厂,阻止操作不会干扰您的用户界面:

Task.Factory.StartNew(Sub()
                       directoryObject.Properties("thumbnailPhoto").Clear()
                       directoryObject.Properties("thumbnailPhoto").Add(imgToByteArray)
                       directoryObject.CommitChanges()           
                      End Sub))