A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

ItemAddEventHandler only runs once



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 16th 07, 02:24 PM posted to microsoft.public.outlook.program_addins
Dave
external usenet poster
 
Posts: 247
Default ItemAddEventHandler only runs once

Hi,

Im trying to catch all incoming new mail using the code below. The problem
is that it is only run once, so when i get 3 new messages, only the first
mail will be used in the eventhandler.

--


private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.MAPIFolder inbox =
Application.Session.GetDefaultFolder(Outlook.OlDef aultFolders.olFolderInbox);
inbox.Items.ItemAdd += new
Outlook.ItemsEvents_ItemAddEventHandler(inboxFolde rItemAdded);
}

public void inboxFolderItemAdded(object item)
{
if (item is Outlook.MailItem)
{
Outlook.MailItem mail = (Outlook.MailItem)item;

MessageBox.Show(mail.Subject.ToString());
}
}

Ads
  #2  
Old April 16th 07, 02:58 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default ItemAddEventHandler only runs once

Declare the inbox object at class level and not in ThisAddIn_Startup and I'd
recommend also declaring an object for inbox.Items and attaching the event
handler to that instead of to inbox.Items as you are doing.

The way that object is declared it's going out of scope and is being garbage
collected.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Dave" wrote in message
...
Hi,

Im trying to catch all incoming new mail using the code below. The problem
is that it is only run once, so when i get 3 new messages, only the first
mail will be used in the eventhandler.

--


private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.MAPIFolder inbox =
Application.Session.GetDefaultFolder(Outlook.OlDef aultFolders.olFolderInbox);
inbox.Items.ItemAdd += new
Outlook.ItemsEvents_ItemAddEventHandler(inboxFolde rItemAdded);
}

public void inboxFolderItemAdded(object item)
{
if (item is Outlook.MailItem)
{
Outlook.MailItem mail = (Outlook.MailItem)item;

MessageBox.Show(mail.Subject.ToString());
}
}


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Installer runs Invisible Outlook - General Queries 2 October 3rd 06 09:53 AM
Macro runs on startup jbc Outlook - Installation 1 September 20th 06 07:40 PM
ThisOutlookSession - code runs only once Rafael1119 Outlook and VBA 8 July 17th 06 11:51 AM
Outlook 2003 "find" contacts doesn't work, just runs and runs Tom Stanley Outlook - Using Contacts 1 July 5th 06 03:56 AM
Outlook Express runs without .exe DiscoNap9000 Outlook Express 3 May 29th 06 11:18 PM


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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.