Asynchronous DirectorySearcher (LDAP)

痴心易碎 提交于 2020-01-24 02:52:08

问题


I am preforming a long search in active directory and would really like to user the DirectorySearcher.Asynchronous = True. Microsoft provides very little documentation on 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.

How is my application to know when the search is done. I don't see any properties, events or callbacks that would provide this notification. Does anyone have any Idea how to get this functionality?

Basically I am looking for this:

  • Start Async Directory Search
  • Return Results to a System.Collections.Concurrent.ConcurrentQueue(Of Object)
  • As DirectorySearcher is running I can process Items added to the Queue

Thanks so much for your help.


回答1:


DirectoryServices uses ADSI to talk to AD. When you set async to true it sets the ADS_SEARCHPREF_ASYNCHRONOUS search preference to true using IDirectorySearch.SetSearchPreferences.

Here is a page that explains the differences between sync and async searches: Synchronous and Asynchronous Searches with IDirectorySearch

This describes paging: Paging with IDirectorySearch

If you are doing a big query you could spawn your own thread or use the thread pool, set the page size to something below 1000, and populate your queue as the results come in.



来源:https://stackoverflow.com/questions/13298855/asynchronous-directorysearcher-ldap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!