ItemAdd event with Outlook2007

D

DavidH&P

hi,
can anyone help me to find what's wrong in my code ?
I'm using VSTOv3 and Outlook2007 beta2,
I try to use the ItemAdd event but any messageBox appear when i move a mail
into the inbox folder or when a new mail arrives into this folder.
-----------------------------
Outlook.NameSpace mapiNamespace = this.GetNamespace("MAPI");
Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)
this.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

Outlook.MAPIFolder oFolderSurveille = inBox;
Outlook.Items oItems = oFolderSurveille.Items;
oItems.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(oItems_ItemAdd);

private void oItems_ItemAdd(object Item)
{
MessageBox.Show("ItemAdd event");
}
 
F

Fidget Brain

try making the oItems field into a class scoped field rather than a local
scoped field. there is a known issue, where an event handler will not fire
for a local scoped field, because it is getting garbage collected.
 
D

DavidH&P

Thanks,

it solves my problem !

Fidget Brain said:
try making the oItems field into a class scoped field rather than a local
scoped field. there is a known issue, where an event handler will not fire
for a local scoped field, because it is getting garbage collected.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top