I have a sample code here which simply looks for the same email subject and
returns the total of number messages located in a folder. But this code took
noticeably longer time to execute compare to the good old Outlook's "Find All
/ Related Messages" feature. This Outlook's feature returns a list in an
instant without delay while this sample code took at least 2 or more seconds
to return just a number.
==================== begin ==================
private int FindEmailsWithSameSubject(string EmailSubject)
int MessageFound = 0;
// The following two variables are declared
// private Outlook.Application App;
// private Outlook.Explorer CurrentExplorer;
// and defined globally in the main class:
// App = new Outlook.Application();
// CurrentExplorer = App.ActiveExplorer();
Outlook.MAPIFolder SelectedFolder =
foreach (Object SelectedObject in SelectedFolder.Items)
// Only work on messages which are email items.
if (SelectedObject is Outlook.MailItem)
Outlook.MailItem MailItem = SelectedObject as Outlook.MailItem;
if (EmailSubject == MailItem.Subject)
==================== end ==================
This code is executed on an inbox with just 190 messages.
1) Why this code take a longer time to run?
2) Is there a better way to find all related messages?
Thanks a lot.