How to handle event in outlook add-in? -
it work 1 time, event handler not work.i not understand why?
private void thisaddin_startup(object sender, system.eventargs e) { var folder = globals.thisaddin.application.session.defaultstore. getdefaultfolder(outlook.oldefaultfolders.olfoldertasks); foreach(outlook.taskitem item in folder.items) { item.beforedelete += beforedelete; item.save(); } } private void beforedelete(object item, ref bool cancel) { messagebox.show("Удалено"); // marshal.releasecomobject(item); must it? }
the object raises event must alive raise events. in case setting event sync on local variable gets garbage collected , hence not raise events anymore. keep object referenced on global (class) level. case, needs list of taskitem objects.
that being said, not ever set event sinks on all items in folder. kill outlook. since user needs select item before attempting delete it, process explorer.selectionchange event, clear list of items, set event sinks on items explorer.selection collection
Comments
Post a Comment