PC Review


Reply
Thread Tools Rate Thread

Another way to detect if email read?

 
 
Mark B
Guest
Posts: n/a
 
      11th Nov 2009
VSTO, 2007, C#.

I'm going through the code of our senior developer to try and reduce the
load-time of the Outlook Add-on.

I see he is adding an event handler to all email items on ThisAddIn_Startup
so he can detect when an email is read. (He uses this info for something
else we need). It all works fine but I have noticed in testing it gets
pretty slow as more emails are stored in Outlook. I've got around 50 and the
delay is too long already...

He did have one for On-Email-Send but I removed that code and put a "folder
watch" event on the SentItems folder instead.

I am just trying to think of any way I can do something similar or an
alternative for detecting if an email is read. Any ideas?



private void ThisAddIn_Startup(object sender, System.EventArgs e)
{

.....

Outlook.Stores stores =
Globals.ThisAddIn.Application.GetNamespace("MAPI").Stores;
foreach (Outlook.Store store in stores)
{
foreach (Outlook.Folder f in store.GetRootFolder().Folders)
{
foreach (object i in f.Items)
{
if (i != null && i is Outlook.MailItem)
{
EmailsEventHandler.AddHandlers((Outlook.MailItem)i);
}
}
}
}

.....
}

public static bool AddHandlers(Outlook.MailItem mail)
{
bool result = true;
readEventHandlers.Add(new EmailReadEventHandler(mail));
return result;
}

 
Reply With Quote
 
 
 
 
Sue Mosher [MVP]
Guest
Posts: n/a
 
      11th Nov 2009
Have you considered using the Application.ItemLoad event along with a
wrapper class to handle multiple items being loaded?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Mark B" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> VSTO, 2007, C#.
>
> I'm going through the code of our senior developer to try and reduce the
> load-time of the Outlook Add-on.
>
> I see he is adding an event handler to all email items on
> ThisAddIn_Startup so he can detect when an email is read. (He uses this
> info for something else we need). It all works fine but I have noticed in
> testing it gets pretty slow as more emails are stored in Outlook. I've got
> around 50 and the delay is too long already...
>
> He did have one for On-Email-Send but I removed that code and put a
> "folder watch" event on the SentItems folder instead.
>
> I am just trying to think of any way I can do something similar or an
> alternative for detecting if an email is read. Any ideas?
>
>
>
> private void ThisAddIn_Startup(object sender, System.EventArgs e)
> {
>
> ....
>
> Outlook.Stores stores =
> Globals.ThisAddIn.Application.GetNamespace("MAPI").Stores;
> foreach (Outlook.Store store in stores)
> {
> foreach (Outlook.Folder f in store.GetRootFolder().Folders)
> {
> foreach (object i in f.Items)
> {
> if (i != null && i is Outlook.MailItem)
> {
>
> EmailsEventHandler.AddHandlers((Outlook.MailItem)i);
> }
> }
> }
> }
>
> ....
> }
>
> public static bool AddHandlers(Outlook.MailItem mail)
> {
> bool result = true;
> readEventHandlers.Add(new EmailReadEventHandler(mail));
> return result;
> }
>



 
Reply With Quote
 
Mark B
Guest
Posts: n/a
 
      11th Nov 2009
No but I wonder if that handles the email being read in the preview pane
though. Think it would? I think a lot of people just use that these days to
read emails.


"Sue Mosher [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Have you considered using the Application.ItemLoad event along with a
> wrapper class to handle multiple items being loaded?
>
> --
> Sue Mosher, Outlook MVP
> Author of Microsoft Outlook 2007 Programming:
> Jumpstart for Power Users and Administrators
> http://www.outlookcode.com/article.aspx?id=54
>
>
> "Mark B" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> VSTO, 2007, C#.
>>
>> I'm going through the code of our senior developer to try and reduce the
>> load-time of the Outlook Add-on.
>>
>> I see he is adding an event handler to all email items on
>> ThisAddIn_Startup so he can detect when an email is read. (He uses this
>> info for something else we need). It all works fine but I have noticed in
>> testing it gets pretty slow as more emails are stored in Outlook. I've
>> got around 50 and the delay is too long already...
>>
>> He did have one for On-Email-Send but I removed that code and put a
>> "folder watch" event on the SentItems folder instead.
>>
>> I am just trying to think of any way I can do something similar or an
>> alternative for detecting if an email is read. Any ideas?
>>
>>
>>
>> private void ThisAddIn_Startup(object sender, System.EventArgs e)
>> {
>>
>> ....
>>
>> Outlook.Stores stores =
>> Globals.ThisAddIn.Application.GetNamespace("MAPI").Stores;
>> foreach (Outlook.Store store in stores)
>> {
>> foreach (Outlook.Folder f in
>> store.GetRootFolder().Folders)
>> {
>> foreach (object i in f.Items)
>> {
>> if (i != null && i is Outlook.MailItem)
>> {
>>
>> EmailsEventHandler.AddHandlers((Outlook.MailItem)i);
>> }
>> }
>> }
>> }
>>
>> ....
>> }
>>
>> public static bool AddHandlers(Outlook.MailItem mail)
>> {
>> bool result = true;
>> readEventHandlers.Add(new EmailReadEventHandler(mail));
>> return result;
>> }
>>

>
>


 
Reply With Quote
 
Mark B
Guest
Posts: n/a
 
      11th Nov 2009
Standby -- just reading your book:

http://books.google.co.nz/books?id=J...emLoad&f=false




"Mark B" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> No but I wonder if that handles the email being read in the preview pane
> though. Think it would? I think a lot of people just use that these days
> to read emails.
>
>
> "Sue Mosher [MVP]" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Have you considered using the Application.ItemLoad event along with a
>> wrapper class to handle multiple items being loaded?
>>
>> --
>> Sue Mosher, Outlook MVP
>> Author of Microsoft Outlook 2007 Programming:
>> Jumpstart for Power Users and Administrators
>> http://www.outlookcode.com/article.aspx?id=54
>>
>>
>> "Mark B" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> VSTO, 2007, C#.
>>>
>>> I'm going through the code of our senior developer to try and reduce the
>>> load-time of the Outlook Add-on.
>>>
>>> I see he is adding an event handler to all email items on
>>> ThisAddIn_Startup so he can detect when an email is read. (He uses this
>>> info for something else we need). It all works fine but I have noticed
>>> in testing it gets pretty slow as more emails are stored in Outlook.
>>> I've got around 50 and the delay is too long already...
>>>
>>> He did have one for On-Email-Send but I removed that code and put a
>>> "folder watch" event on the SentItems folder instead.
>>>
>>> I am just trying to think of any way I can do something similar or an
>>> alternative for detecting if an email is read. Any ideas?
>>>
>>>
>>>
>>> private void ThisAddIn_Startup(object sender, System.EventArgs e)
>>> {
>>>
>>> ....
>>>
>>> Outlook.Stores stores =
>>> Globals.ThisAddIn.Application.GetNamespace("MAPI").Stores;
>>> foreach (Outlook.Store store in stores)
>>> {
>>> foreach (Outlook.Folder f in
>>> store.GetRootFolder().Folders)
>>> {
>>> foreach (object i in f.Items)
>>> {
>>> if (i != null && i is Outlook.MailItem)
>>> {
>>>
>>> EmailsEventHandler.AddHandlers((Outlook.MailItem)i);
>>> }
>>> }
>>> }
>>> }
>>>
>>> ....
>>> }
>>>
>>> public static bool AddHandlers(Outlook.MailItem mail)
>>> {
>>> bool result = true;
>>> readEventHandlers.Add(new EmailReadEventHandler(mail));
>>> return result;
>>> }
>>>

>>
>>

>


 
Reply With Quote
 
Mark B
Guest
Posts: n/a
 
      11th Nov 2009
Looks like I can research
http://blogs.msdn.com/jannemattila/a...-vsto-3-0.aspx


 
Reply With Quote
 
Sue Mosher [MVP]
Guest
Posts: n/a
 
      11th Nov 2009
Yes, I think that's one of the reasons it was added -- to provide a better
way to handle that event.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Mark B" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> No but I wonder if that handles the email being read in the preview pane
> though. Think it would? I think a lot of people just use that these days
> to read emails.
>
>
> "Sue Mosher [MVP]" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Have you considered using the Application.ItemLoad event along with a
>> wrapper class to handle multiple items being loaded?
>>
>> "Mark B" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> VSTO, 2007, C#.
>>>
>>> I'm going through the code of our senior developer to try and reduce the
>>> load-time of the Outlook Add-on.
>>>
>>> I see he is adding an event handler to all email items on
>>> ThisAddIn_Startup so he can detect when an email is read. (He uses this
>>> info for something else we need). It all works fine but I have noticed
>>> in testing it gets pretty slow as more emails are stored in Outlook.
>>> I've got around 50 and the delay is too long already...
>>>
>>> He did have one for On-Email-Send but I removed that code and put a
>>> "folder watch" event on the SentItems folder instead.
>>>
>>> I am just trying to think of any way I can do something similar or an
>>> alternative for detecting if an email is read. Any ideas?
>>>
>>>
>>>
>>> private void ThisAddIn_Startup(object sender, System.EventArgs e)
>>> {
>>>
>>> ....
>>>
>>> Outlook.Stores stores =
>>> Globals.ThisAddIn.Application.GetNamespace("MAPI").Stores;
>>> foreach (Outlook.Store store in stores)
>>> {
>>> foreach (Outlook.Folder f in
>>> store.GetRootFolder().Folders)
>>> {
>>> foreach (object i in f.Items)
>>> {
>>> if (i != null && i is Outlook.MailItem)
>>> {
>>>
>>> EmailsEventHandler.AddHandlers((Outlook.MailItem)i);
>>> }
>>> }
>>> }
>>> }
>>>
>>> ....
>>> }
>>>
>>> public static bool AddHandlers(Outlook.MailItem mail)
>>> {
>>> bool result = true;
>>> readEventHandlers.Add(new EmailReadEventHandler(mail));
>>> return result;
>>> }
>>>

>>
>>

>



 
Reply With Quote
 
Mark B
Guest
Posts: n/a
 
      12th Nov 2009
Thanks for your help Sue. I've coded it now and it works well.

"Sue Mosher [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Yes, I think that's one of the reasons it was added -- to provide a better
> way to handle that event.
>
> --
> Sue Mosher, Outlook MVP
> Author of Microsoft Outlook 2007 Programming:
> Jumpstart for Power Users and Administrators
> http://www.outlookcode.com/article.aspx?id=54
>
>
> "Mark B" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> No but I wonder if that handles the email being read in the preview pane
>> though. Think it would? I think a lot of people just use that these days
>> to read emails.
>>
>>
>> "Sue Mosher [MVP]" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>>> Have you considered using the Application.ItemLoad event along with a
>>> wrapper class to handle multiple items being loaded?
>>>
>>> "Mark B" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> VSTO, 2007, C#.
>>>>
>>>> I'm going through the code of our senior developer to try and reduce
>>>> the load-time of the Outlook Add-on.
>>>>
>>>> I see he is adding an event handler to all email items on
>>>> ThisAddIn_Startup so he can detect when an email is read. (He uses this
>>>> info for something else we need). It all works fine but I have noticed
>>>> in testing it gets pretty slow as more emails are stored in Outlook.
>>>> I've got around 50 and the delay is too long already...
>>>>
>>>> He did have one for On-Email-Send but I removed that code and put a
>>>> "folder watch" event on the SentItems folder instead.
>>>>
>>>> I am just trying to think of any way I can do something similar or an
>>>> alternative for detecting if an email is read. Any ideas?
>>>>
>>>>
>>>>
>>>> private void ThisAddIn_Startup(object sender, System.EventArgs e)
>>>> {
>>>>
>>>> ....
>>>>
>>>> Outlook.Stores stores =
>>>> Globals.ThisAddIn.Application.GetNamespace("MAPI").Stores;
>>>> foreach (Outlook.Store store in stores)
>>>> {
>>>> foreach (Outlook.Folder f in
>>>> store.GetRootFolder().Folders)
>>>> {
>>>> foreach (object i in f.Items)
>>>> {
>>>> if (i != null && i is Outlook.MailItem)
>>>> {
>>>>
>>>> EmailsEventHandler.AddHandlers((Outlook.MailItem)i);
>>>> }
>>>> }
>>>> }
>>>> }
>>>>
>>>> ....
>>>> }
>>>>
>>>> public static bool AddHandlers(Outlook.MailItem mail)
>>>> {
>>>> bool result = true;
>>>> readEventHandlers.Add(new EmailReadEventHandler(mail));
>>>> return result;
>>>> }
>>>>
>>>
>>>

>>

>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: detect if a mail is read in a public folder Sue Mosher [MVP] Microsoft Outlook Program Addins 1 16th Nov 2009 04:30 PM
Detect read messages count changed xhantt Microsoft Outlook Program Addins 0 14th Feb 2006 04:06 PM
Can I detect new sms come and read or delete it? c#? Liren Zhao Microsoft Dot NET Compact Framework 1 26th Jun 2005 11:09 AM
detect if file opens read-only Mal Stone Microsoft Excel Programming 2 7th Apr 2004 03:58 PM
CD-ROM & CD-RW will not read/detect CD's after Windows 98 to XP upgrade Tetsinger Windows XP Hardware 0 8th Nov 2003 09:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:35 AM.