获取Outlook.Store极其缓慢

时间:2016-10-13 06:10:47

标签: vb.net outlook vsto outlook-addin

我正在尝试绑定到Outlook客户端上所有商店的ItemLoad和ItemSend,但速度非常慢。

这是我的代码......

Private Shared WithEvents _explorer As Outlook.Explorer = Nothing
Private Shared WithEvents _inspectors As Outlook.Inspectors

Public Shared Sub Init()
    _explorer = Globals.ThisAddIn.Application.Explorers.Application.ActiveExplorer
    _inspectors = Globals.ThisAddIn.Application.Inspectors

    Dim ns As Outlook.NameSpace = Globals.ThisAddIn.Application.GetNamespace("MAPI")
    Dim stores As Outlook.Stores = ns.Stores
    For i As Integer = 1 To stores.Count
        Try
            Dim store As Outlook.Store = stores(i)
            Dim sentFolder As Outlook.Folder = CType(store.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail), Outlook.Folder)
            Dim sentItem As Outlook.Items = sentFolder.Items
            AddHandler sentItem.ItemAdd, AddressOf MailSendt
            Marshal.ReleaseComObject(store)
        Catch ex As System.Exception
        End Try
    Next
    Marshal.ReleaseComObject(stores)
    Marshal.ReleaseComObject(ns)
End Sub

线......

Dim store As Outlook.Store = stores(i)

......极其缓慢。它可能需要2-4秒 - 当我的用户拥有20-30个商店时,可能需要几分钟才能锁定Outlook。

我们正在使用最新版本的Office 365。

知道如何加快速度吗?

感谢。

0 个答案:

没有答案