【问题标题】:slow performance of outlook addin to get contact item for distribution listOutlook 插件的性能缓慢以获取分发列表的联系人项目
【发布时间】:2017-05-08 19:18:48
【问题描述】:

我有以下代码,它需要花费大量时间从分发列表、交换服务器中检索联系人项目。有什么办法可以调整它的性能

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

如果调试

                 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,

例如消息); 返回空值; }

    }

【问题讨论】:

    标签: c# performance outlook visual-studio-addins


    【解决方案1】:

    首先,永远不要遍历通讯录中的所有条目。您正在匹配一个地址;为什么不使用Namespace.CreateRecipient / Recipient.Resolve

    其次,您假设所有地址条目都来自您的联系人文件夹。 Exchange下的GAL则不是这样,AddressEntry.GetContact()会返回null,导致异常。

    如果您的条目总是来自联系人文件夹,为什么不使用Namespace.GetDefaultFolder(olFolderContacts),然后使用MAPIFolder.Items.Find

    【讨论】:

    • 谢谢德米特里。我需要从本地地址条目以及 GAL 和本地 Outlook 实例中的所有可用地址列表条目中搜索联系项目。我需要检查联系人项目是分发列表还是个人,并取决于要显示的数据。您有任何参考/链接可以查看吗?非常感谢
    • 谢谢我已经通过检查 oAddressEntry.Type == "EX" 或 oAddressEntry.Type == "SMTP" 解决了这个问题。您能否让我知道如何查找发件人/收件人是否是分发列表,并计算与之关联的电子邮件帐户的数量。谢谢
    • 检查是AddressEntry.Members不为空然后检查Members.Count
    猜你喜欢
    • 2016-06-15
    • 1970-01-01
    • 2016-10-22
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多