I have the code below which checks for user group authorization across domains. The code checks for authorization using a various combination of domains:
//build domain combos for lookup
var domainCombos = new List<Tuple<string, string>>();
domainCombos.Add(new Tuple<string, string>("corp-domain-1", "corp-domain-1"));
domainCombos.Add(new Tuple<string, string>("corp-domain-1", "corp-domain-2"));
domainCombos.Add(new Tuple<string, string>("corp-domain-2", "corp-domain-2"));
domainCombos.Add(new Tuple<string, string>("corp-domain-2", "corp-domain-1"));
var results = await Task.WhenAll(domainCombos.Select(domainCombo =>
{
request.GroupDomainName = domainCombo.Item1;
request.UserDomainName = domainCombo.Item2;
return GetSingleAuthorizedGroupInfo(request);
}));
var aggregateResults = results.Where(x => x != null)
.SelectMany(result => result).ToList();
return aggregateResults;
I think that this routine appears to be a good candidate for Parallel.ForEach
b/c there are no interdependencies between calls to GetSingleAuthorizedGroupInfo()
.
Also, when I execute with 1 domainCombo, the response returns in 800ms, whereas when I execute with 4 domainCombos the response returns in about 1800ms. How would I go about converting the code above to leverage Parallel.ForEach
?