我怎样才能把它转换foreach
成Parallel.ForEach()
,
我们正在使用dynamic
变量来获取 Outlook 联系人。
有什么帮助吗?
List<ServiceReference1.Addressbooks> list = new List<ServiceReference1.Addressbooks>();
// dynamic Contacts = outlook.GetNamespace("Mapi").GetDefaultFolder(10);
try
{
dynamic Contacts = outlook.Session.GetDefaultFolder(10);
foreach (var items in Contacts.items)
{
try
{
ServiceReference1.Addressbooks ad = new ServiceReference1.Addressbooks();
ad.FirstName = (string)items.FirstName;
ad.JobTitle = (string)items.JobTitle;
ad.MobileTelephoneNumber = (string)items.MobileTelephoneNumber;
ad.BusinessTelephoneNumber = (string)items.BusinessTelephoneNumber;
ad.BusinessFaxNumber = (string)items.BusinessFaxNumber;
ad.Email1Address = (string)items.Email1Address;
ad.Body = items.Body.Length > 999 ? (items.Body).Substring(0, 999) : items.Body;
ad.CompanyName = (string)items.CompanyName;
ad.LastModificationTime = (DateTime)items.LastModificationTime;
list.Add(ad);
}
catch (Exception exp)
{
throw exp;
}
}
}
catch
{
}
return list;
最好的问候, Prasanth.k