Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous DirectorySearcher (LDAP)

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.

like image 849
Dakota K Avatar asked Nov 08 '12 22:11

Dakota K


1 Answers

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.

like image 109
AbdElRaheim Avatar answered Oct 03 '22 08:10

AbdElRaheim