VSTO展望 - 联系迭代这么慢!迭代、VSTO

2023-09-04 23:18:28 作者:为消逝的时光默哀

我工作的一个Outlook插件,我有一个对话窗口,允许用户选择联系人。我还没有能够找到一种方法,使用Outlook联系人窗口,所以我通过ContactFolder.Items循环,做我的工作的方式。

I'm working on an outlook add-in and I have a dialog window that allows the user to select contacts. I havent been able to find a way to use the outlook contact window so I am looping through the ContactFolder.Items and doing my work that way.

现在的问题是,我要处理高达70K的接触。我试着多线程和许多其他的东西,但它仅仅是如此之慢。它需要15秒的负载30K接触。

The problem is that I have to handle up to 70K contacts. I tried multi-threading and many other things but it is just so slow. It takes 15 seconds to load 30k contacts.

我可以加载并结合500K POCO对象,以毫秒为单位,但是当我需要从Outlook联系人的项目,它只是需要永远。这个问题似乎是,当你真正需要从它从数据库或东西取它contactitem获取属性。是否有接触缓存我可以拉?我只需要显示和电子邮件,没有别的。一个ID将是不错,但我并不需要它。

I can load and bind 500k POCO objects in milliseconds but when I need to get the contact items from outlook it just takes forever. The problem seems to be when you actually need to get a property from the contactitem it has to fetch it from the database or something. Is there a contact cache I can pull from? I only need Display and Email, nothing else. An ID would be nice but I don't need it.

有人能告诉我越来越从Outlook联系人中有更好的办法,或者至少告诉我怎么打开Outlook联系人选择窗口?我能找到code打开它,但它不会让我,因为我展示一个模式对话框,它不会打开,如果有一个模式开放。

Can someone please tell me a better way of getting contacts from outlook or at least tell me how to open the outlook contact selection window? I was able to find code to open it but it wont let me because I'm showing a modal dialog and it wont open if there is a modal open.

推荐答案

答:

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() });

  }

这载荷小于第二是速度不够快,把它放回在UI线程上。

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