R
ray
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?
IEnumerable<Outlook.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;
}
}
}
}
the MailItems – fast. The solution below is very slow due to “x as
Outlook.Item†call.
Is there a faster way to do this?
IEnumerable<Outlook.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;
}
}
}
}