问题
I'm seeing a situation where the RecurrencePattern.Exceptions object, at least the Count property in Outlook 2010, is not always being updated after an occurrence of the recurring event is modified or deleted; sometimes it is, but more often it is not. At this point I'm not sure if the RecurrencePattern.Exceptions.Count is the only property not being updated, or if it is the entire Exceptions collection.
When I restart Outlook and my add-in, all changes from previous sessions are reflected ... but subsequent changes only show up sometimes.
Is this a known bug in Outlook, and if so is it only in Outlook 2010? Are there any workarounds? This is for an add-in that does real-time updates to a SQL contact/calendar database.
回答1:
As Eugene mentioned, you need to completely dereference the appointment item. Even then, Outlook really likes to cache the last accessed appointment, and you need to open another appointment for Outlook to release the previous one.
Do you see the data updated on the low level (MAPI)? Using OutlookSpy, select the appointment and click the IMessage button on the OutlookSpy ribbon; take a look at the AppointmentRecur named property. Does OutlookSpy show the right exception count?
UPDATE:
if Redemption is an option, you can try to use its RDOAppointmentItem object (the Item variable below can point to your appointment). If you want to avoid stale data, replace GetRDOObjectFromOutlookObject belwo with GetMessageFromID.
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Item = Session.GetMessageFromID(Application.ActiveExplorer.Selection(1).EntryID)
set RdoItem = Session.GetRDOObjectFromOutlookObject(Item)
set RecurPattern = RdoItem.GetRecurrencePattern
MsgBox RecurPattern.Exceptions.Count
回答2:
Here is what MSDN states:
When you work with recurring appointment items, you should release any prior references, obtain new references to the recurring appointment item before you access or modify the item, and release these references as soon as you are finished and have saved the changes. This practice applies to the recurring AppointmentItem object, and any Exception or RecurrencePattern object. To release a reference in Visual Basic for Applications (VBA) or Visual Basic, set that existing object to Nothing. In C#, explicitly release the memory for that object.
Note that even after you release your reference and attempt to obtain a new reference, if there is still an active reference, held by another add-in or Outlook, to one of the above objects, your new reference will still point to an out-of-date copy of the object. Therefore, it is important that you release your references as soon as you are finished with the recurring appointment.
In C# 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. See Systematically Releasing Objects for more information.
来源:https://stackoverflow.com/questions/31298414/outlook-recurrencepattern-exceptions-count-not-updated-after-occurrence-modified