Outlook VSTO-保存AppointmentItem父级 [英] Outlook VSTO - Save AppointmentItem Parent

查看:178
本文介绍了Outlook VSTO-保存AppointmentItem父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存约会系列主题.这按预期工作,但保存后,当我执行move/edit日历项目时,出现此错误.

I'm trying to save a appointment series subject. This works as expected but after the save, When I performed move/edit the calendar item, I get this error.

重现错误的代码.

  public void OnMyButtonClickContext(Office.IRibbonControl control)
    {

        var sel = control.Context as Microsoft.Office.Interop.Outlook.Selection;
        var i = sel[1] as Microsoft.Office.Interop.Outlook.AppointmentItem;

        i.Parent.Subject = i.Parent.Subject + " [CONFIRMED]";
        i.Parent.Save();

    }

我尝试使用Marhsal.ReleaseComObject(i)将i设置为null.似乎都没有帮助.

I've tried setting i to null, using Marhsal.ReleaseComObject(i). Neither of which seems to help.

推荐答案

我在代码中没有看到任何发布的COM对象语句.您究竟尝试释放哪些对象?

I don't see any release COM objects statements in the code. What objects exactly did you try to release?

为什么总是使用AppointmentItem类的Parent属性?

Why do you always use the Parent property of the AppointmentItem class?

每次调用Parent属性时,引用计数器都会增加.然后您需要在代码中释放此类对象.

Each time you call the Parent property you get the reference counter increased. And then you need to release such objects in the code.

使用 System.Runtime.InteropServices.Marshal .ReleaseComObject 用于在使用完Outlook对象后将其释放.然后在Visual Basic中将变量设置为Nothing(在C#中为null)以释放对该对象的引用. 在系统地释放对象文章.

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. Read more about that in the Systematically Releasing Objects article.

这是MSDN所声明的:

Here is what MSDN states for that:

在使用定期约会项目时,应释放任何先前的参考,在访问或修改项目之前获取对定期约会项目的新参考,并在完成并保存更改后立即释放这些参考.此做法适用于重复的AppointmentItem对象以及任何Exception或RecurrencePattern对象.要在Visual Basic for Applications(VBA)或Visual Basic中发布引用,请将现有对象设置为Nothing.在C#中,显式释放该对象的内存.

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.

请注意,即使在释放参考并尝试获取新参考之后,如果仍然存在由另一个加载项或Outlook持有的上述对象之一的活动参考,则新参考仍将指向对象的过期副本.因此,重要的是,您必须在定期约会结束后立即释放引用.

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.

看起来您没有在代码中释放所有底层的COM对象.

Looks like you didn't release all underlying COM objects in the code.

这篇关于Outlook VSTO-保存AppointmentItem父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆