VSTO Outlook - Contact iteration is SO SLOW!

怎甘沉沦 提交于 2019-12-06 15:49:23

Answer:

Microsoft.Office.Interop.Outlook.NameSpace ns = Globals.ThisAddIn.Application.GetNamespace("MAPI");
  Microsoft.Office.Interop.Outlook.MAPIFolder contactsFld = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);

  Microsoft.Office.Interop.Outlook.Table tb = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts).GetTable(null, Microsoft.Office.Interop.Outlook.OlItemType.olContactItem);

  tb.Columns.RemoveAll();
  tb.Columns.Add("Email1Address");
  tb.Columns.Add("FullName");

  object[,] otb = tb.GetArray(100000) as object[,];
  int len = otb.GetUpperBound(0);

  for (int i = 0; i < len; i++)
  {
    if (otb[i, 0] == null)
    {
      continue;
    }
    Contacts.Add(new ContactItem() { ContactDisplay = otb[i, 1].ToString(), ContactEmail = otb[i, 0].ToString() });

  }

This loads in less than a second which is fast enough to put it back on the UI thread.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!