问题
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