Events not firing?

K

kwendex

I'm trying to hook into FolderChange and ItemChange and ItemAdd events
to the inbox and yet actions (that I believe should) fire these events
do not result in my callbacks being called consistently, and I'm
wondering if there is some kind of quirk in Outlook 2003 that is making
this so (or whether I'm just an idiot). I set event handlers for these
events and send myself mail - yet only SOMETIMES do my event methods
get called.

I'm using .Net and the new (yes, it's Beta) VSTO feature for Outlook
and so it's possible I'm running into Beta blues here...but I'm not
sure.

I can share code but it's fairly straightforward as it's .Net - but the
bottom line question is: Has anyone ever experienced the event-model in
Outlook 2003 being somewhat inconsistent, and is it possible that
callbacks may not fire consistently for reasons outside of me being
braindead? If not - then I'm obviously doing something wrong.

Thanks in advance,
Ben
 
S

Sue Mosher [MVP-Outlook]

The most common events issue in .NET applications is having your object go out of scope and be cleaned up by the garbage collector. Such event-enabled objects generally need to be declared at the module level so they'll persist for the lifetime of the application. If you are monitoring more than one folder, this means using an Arraylist or Hashtable to hold references to the objects in a wrapper class.

Also, ItemChange and ItemAdd will not fire if more than 16 items are changed or added at once. This is a known limitation, not limited to ..NET applications.
 
B

Ben Rush

Sue,

Thank you for your time in responding to my inquiry. I had thought about
that as I started watching things behave intermittently, but I could not
identify where the orphaned object was being declared and then I woke up
this morning, read your post and it suddenly hit me that I was, indeed,
being braindead. Basically I was doing something like this in the
ThisAppliaction_Startup procedure:

this.MAPINamespaceInterface.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox).Items
+= BLAH;

Basically the GetDefaultFolder was doing a QueryInterface under the hood (I
suspect) and the object was having its connection points hydrated through my
+= statement, and then it simply went out of scope. The fix was to create:

private Outlook.Items InboxItems;

So the interface wouldn't go out of scope. Thanks Sue, much appreciated for
the kick to the head,

Ben


The most common events issue in .NET applications is having your object go
out of scope and be cleaned up by the garbage collector. Such event-enabled
objects generally need to be declared at the module level so they'll persist
for the lifetime of the application. If you are monitoring more than one
folder, this means using an Arraylist or Hashtable to hold references to the
objects in a wrapper class.

Also, ItemChange and ItemAdd will not fire if more than 16 items are changed
or added at once. This is a known limitation, not limited to .NET
applications.
 

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