Asynchronous DirectorySearcher (LDAP)

I am doing a preliminary long search in the active directory and would really like to use the DirectorySearcher.Asynchronous = True function. Microsoft provides very little MSDN documentation

Asynchronous search can show results as they are found while simultaneously searching for additional results. This is useful for filling out lists.

By default, this property is set to false.

How my application will know when the search is complete. I do not see any properties, events or callbacks that would provide this notification. Does anyone have an idea how to get this functionality?

I am mainly looking for:

  • Starting a search in Async Directory
  • Returns results in System.Collections.Concurrent.ConcurrentQueue (Of Object)
  • How DirectorySearcher Works, I Can Handle Items Added To The Queue

Many thanks for your help.

+8
directoryservices
source share
1 answer

DirectoryServices uses ADSI to communicate with AD. When you set async to true, it sets the preference parameter ADS_SEARCHPREF_ASYNCHRONOUS to true using IDirectorySearch.SetSearchPreferences.

Here is a page that explains the differences between synchronization and asynchronous search. http://msdn.microsoft.com/en-us/library/windows/desktop/aa746498(v=vs.85).aspx

This describes the paging. http://msdn.microsoft.com/en-us/library/windows/desktop/aa746414(v=vs.85).aspx

If you are making a large request, you can create your own thread or use the thread pool, set the page size to something below 1000 and fill in the queue as the results arrive.

+1
source share

All Articles