I have the following code it takes lot of time to retrieve contact items from the distribution list, exchange server. Is there anything can be done to tune it s performance
public Outlook.AddressEntry GetDistributionListMembers(string sParamName,Outlook.Application _OutlookApp) { try { List<string> allAddressEntriesList = new List<string>(); Outlook.AddressLists addrLists = _OutlookApp.ActiveExplorer().Session.AddressLists; var receipientContactList = new List<Outlook.AddressEntry>(); foreach (Outlook.AddressList addrList in addrLists) { if (addrList.AddressEntries.Count <= 0) continue; receipientContactList.AddRange(addrList.AddressEntries.Cast<Outlook.AddressEntry>() .Where(x => x.Address.ToLower().Equals(sParamName.ToLower())));
if debug
Debug.print(addrList.Name);
endif
if (receipientContactList.Count > 0) break; } return receipientContactList.FirstOrDefault(x => x.GetContact().HasPicture) ?? receipientContactList.FirstOrDefault(); } catch (System.Exception ex) { WriteLog(System.Reflection.MethodBase.GetCurrentMethod().Name,
ex.Message); return null; }
}