![]() |
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()); } } |
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()); } } |
All times are GMT +1. The time now is 09:24 PM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com