我正在使用这部分代码使用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
答案 0 :(得分:0)
您可以使用任务工厂,阻止操作不会干扰您的用户界面:
Task.Factory.StartNew(Sub()
directoryObject.Properties("thumbnailPhoto").Clear()
directoryObject.Properties("thumbnailPhoto").Add(imgToByteArray)
directoryObject.CommitChanges()
End Sub))