gpt4 book ai didi

.net - 异步目录搜索器 (LDAP)

转载 作者:行者123 更新时间:2023-12-02 02:52:48 27 4
gpt4 key购买 nike

我正在 Active Directory 中执行长时间搜索,并且非常想使用 DirectorySearcher.Asynchronous = True。 Microsoft 提供的有关 MSDN 的文档非常少

An asynchronous search can show results as they are found while simultaneously searching for additional results. This is useful for tasks such as populating list boxes.

The default setting for this property is false.

我的应用程序如何知道搜索何时完成。我没有看到任何可以提供此通知的属性、事件或回调。有人知道如何获得此功能吗?

基本上我正在寻找这个:

  • 启动异步目录搜索
  • 将结果返回到 System.Collections.Concurrent.ConcurrentQueue(Of Object)
  • 当 DirectorySearcher 运行时,我可以处理添加到队列中的项目

非常感谢您的帮助。

最佳答案

DirectoryServices 使用 ADSI 与 AD 对话。当您将 async 设置为 true 时,它​​会使用 IDirectorySearch.SetSearchPreferences 将 ADS_SEARCHPREF_ASYNCHRONOUS 搜索首选项设置为 true。

以下页面解释了同步搜索和异步搜索之间的差异:Synchronous and Asynchronous Searches with IDirectorySearch

这描述了分页:Paging with IDirectorySearch

如果您正在进行大型查询,您可以生成自己的线程或使用线程池,将页面大小设置为低于 1000,并在结果出现时填充您的队列。

关于.net - 异步目录搜索器 (LDAP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13298855/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com