Implementing Parallel.ForEach with a SearchResultCollection:
The below piece of code helps to check the given user is a part of the given active directory group. To implement Parallel.ForEach with a SearchResultCollection, do the casting with the SearchResult object and covert it into a list.
//// Directory Searcher
var directorySearcher = new DirectorySearcher(string.Format("(CN={0})", groupName));
//// Find group
var searchResultCollection = directorySearcher.FindAll().Cast().ToList();
Parallel.ForEach(searchResultCollection, searchResult =>
{
// enumerate members
var resultPropColl = searchResult.Properties;
Parallel.ForEach(resultPropColl["member"].Cast
The below piece of code helps to check the given user is a part of the given active directory group. To implement Parallel.ForEach with a SearchResultCollection, do the casting with the SearchResult object and covert it into a list.
//// Directory Searcher
var directorySearcher = new DirectorySearcher(string.Format("(CN={0})", groupName));
//// Find group
var searchResultCollection = directorySearcher.FindAll().Cast
Parallel.ForEach(searchResultCollection, searchResult =>
{
// enumerate members
var resultPropColl = searchResult.Properties;
Parallel.ForEach(resultPropColl["member"].Cast