View Single Post
  #1  
Old February 20th 09, 07:22 PM posted to microsoft.public.outlook.program_forms
Ray
external usenet poster
 
Posts: 51
Default Faster Folder traversal

I'm having a performance problem with an Outlook AddIn. We need to find all
the MailItems – fast. The solution below is very slow due to “x as
Outlook.Item” call.

Is there a faster way to do this?

IEnumerableOutlook.MailItem GetAllMail(Outlook.Folders folders)
{
foreach (Outlook.MAPIFolder f in folders) {
foreach (var e in GetAllMail(f.Folders)) {
yield return e;
}
foreach (var x in f.Items) {
var e = x as Outlook.MailItem;
if (e != null) {
yield return e;
}
}
}
}

Ads