I have a problem with attaching an event handler to an ItemAdd
event of a public folder.
The problem is the event handler stops being called after a few successful calls.
The code is trivial. I have a ThisAddIn
class which creates an object which in turn attaches a function to the ItemAdd
event in its constructor. The function just pops up a messagebox.
Please point me in the right direction. I simply don't understand where to look for the error.
Thank you in advance, Anatoly
Here is the test code I try to run:
public partial class ThisAddIn
{
internal static Outlook.Folder posts_folder = null;
private static test t;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
t = new test();
}
{
class test
{
public test()
{
System.Windows.Forms.MessageBox.Show("Attaching...");
ThisAddIn.posts_folder.Items.ItemAdd +=new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
}
void Items_ItemAdd(object Item)
{
System.Windows.Forms.MessageBox.Show((Item as Outlook.PostItem).Subject);
}
}