none
How do I capture AppointmentItem events in a shared calendar? RRS feed

  • Question

  • My Add-In processes the events of the AppointmentItem object.

    For the logged in user, everything works fine.  However, it doesn't work consistantly when dealing with a Shared Calendar

    When Outlook starts I get all the shared calendars and store them in a Dictionary object (declared at class level to avoid garbage collection).

    Whenever a new appointment is Added to the Shared calendar (Folder.Items.ItemAdd event) or an AppointmentItem is selected, I add it to a collection for further processing.  I use the same code that is being used for the logged in user.

    The Folder events in the Shared Calendar fire consitently; no problem there.  However, the AppointmentItem events fire a few times when I make changes to the appointment ... other times they won't fire.  Then they fire again.  

    I'm just not sure of what's happening.  Any ideas?

    Monday, June 23, 2014 1:27 PM

Answers

  • Hello Geman,

    First of all, please make sure that the Items class is not swiped by the garbage collector too.

    Be aware, the ItemAdd event is not fired if multiple items are added simultaneously (more than 16). Here is what MSDN states:

    This event does not run when a large number of items are added to the folder at once.

    As a workaround, you can use a timer and track changes in the folders.

    Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. If you do not release these objects in a timely manner, you can reach the limit imposed by Exchange on the maximum number of items opened at any one time. You can read more about this in the  Systematically Releasing Objects article in MSDN.

    • Marked as answer by Germán_MSO Monday, June 23, 2014 6:17 PM
    Monday, June 23, 2014 1:47 PM

All replies

  • Hello Geman,

    First of all, please make sure that the Items class is not swiped by the garbage collector too.

    Be aware, the ItemAdd event is not fired if multiple items are added simultaneously (more than 16). Here is what MSDN states:

    This event does not run when a large number of items are added to the folder at once.

    As a workaround, you can use a timer and track changes in the folders.

    Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. If you do not release these objects in a timely manner, you can reach the limit imposed by Exchange on the maximum number of items opened at any one time. You can read more about this in the  Systematically Releasing Objects article in MSDN.

    • Marked as answer by Germán_MSO Monday, June 23, 2014 6:17 PM
    Monday, June 23, 2014 1:47 PM
  • Thanks.  I'll make the adjustments you've mentioned now and get right back to you.
    Monday, June 23, 2014 2:12 PM
  • They are working now, but I'm cautiously optimistic.  They've worked before then stopped working.

    However, a bright spot is that they're working in folders that I haven't had success in prior to this thread.

    Adjustment I've made:

    Added ReleseComObject.  I was assigning null, but not releasing it first.

    Also, I see just realized a more fundamental problem with my approach in general thanks to the article.  I will update this thread shortly.

    Thanks!!

    Monday, June 23, 2014 2:49 PM
  • I'm getting the results I want now; the AppointmentItem events in the shared calendar are firing consistantly. 

    I'm having some other issues now, but it's not related.  I need to clean up my reference counting.

    Thanks for your help

    Monday, June 23, 2014 6:17 PM