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

标签 .net vb.net directoryservices

我正在 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/

相关文章:

c# - 单独的选项类、重载构造函数或具有默认值的公共(public)属性?

c# - 加载程序集和版本控制

.net - 将 MIME 树转换为 MailMessage

.net - 是否可以从URL读取到System.IO.Stream对象?

php - 如果 SQL 语句有效,则重定向到 URL - ASP.NET 与 PHP

c# - 在 C# 中是否可以直接读取属性(而不是循环访问 PropertyNames)

c# - System.DirectoryServices.Protocols Paged get all users 代码突然停止获取超过第一页的用户

.net - 什么会导致程序集构建版本和运行时版本不同?

c# - 如何通过 LDAP + SSL 验证 Active Directory 凭据?

javascript - 如何使用 vb.net 窗口应用程序打开没有菜单栏的 html 文件