Outlook 插件移动邮件项目很慢
Outlook plugin move mail item is slow
我正在开发一个用于将电子邮件移动到文件夹的 outlook 插件。
工作正常但看起来 MailItem 的移动方法很慢需要 4-5 秒才能移动 10 封电子邮件
我正在使用类似
的东西
for (int i = folder.Items.Count; i > 0; i--)
{
Outlook.MailItem mi = (Outlook.MailItem)theRootFolder.Items[i];
if (mi != null)
{
mi.Move(destFolder);
}
不要在单行代码中使用多个点:
folder.Items.Count
打破 属性 和方法调用的链条,并在单独的代码行中声明每个调用。因此,您将能够立即释放底层 COM 对象。使用 MSDN 中的 System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. This is particularly important if your add-in attempts to enumerate more than 256 Outlook items in a collection that is stored on a Microsoft Exchange Server. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. Read more about that in the Systematically Releasing Objects 文章。
请注意,MailItem 的 Move
方法 class returns 一个应该在之后释放的对象。
我正在开发一个用于将电子邮件移动到文件夹的 outlook 插件。 工作正常但看起来 MailItem 的移动方法很慢需要 4-5 秒才能移动 10 封电子邮件 我正在使用类似
的东西for (int i = folder.Items.Count; i > 0; i--)
{
Outlook.MailItem mi = (Outlook.MailItem)theRootFolder.Items[i];
if (mi != null)
{
mi.Move(destFolder);
}
不要在单行代码中使用多个点:
folder.Items.Count
打破 属性 和方法调用的链条,并在单独的代码行中声明每个调用。因此,您将能够立即释放底层 COM 对象。使用 MSDN 中的 System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. This is particularly important if your add-in attempts to enumerate more than 256 Outlook items in a collection that is stored on a Microsoft Exchange Server. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. Read more about that in the Systematically Releasing Objects 文章。
请注意,MailItem 的 Move
方法 class returns 一个应该在之后释放的对象。