View Single Post
  #2  
Old November 20th 06, 03:29 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Unsubscribing from events (VSTO, C#)

See if it helps if your code unsubscribes like this:

tasksItems.ItemRemove -= new
Outlook.ItemsEvents_ItemRemoveEventHandler(OnTasks Delete);

If that doesn't help you might have to call the garbage collector and wait
for finality before you proceed with your deletion code.

You also should use a count down for loop or other type of loop where you
check for the count of items rather than a foreach loop. The count is
essentially being decremented within the loop as you delete items in a count
up for loop or foreach loop and that messes with things. Often you only get
every other item deleted.


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


wrote in message
oups.com...
In my add-in I have a method that unsubcribes from delete event
handler(it was previously subscribed to) in the begining and subscribes
to it again at the end like:

public void SynchronizeTasks(...)
{
tasksItems.ItemRemove -= OnTasksDelete;

....
foreach (Outlook.TaskItem task in tasksItems)
{
task.Delete();
}
....

tasksItems.ItemRemove += new
Outlook.ItemsEvents_ItemRemoveEventHandler(OnTasks Delete);
}

However, for every task deleted in this method I catch an ItemRemove
event in OnTasksDelete. Is there any way to completely unsubscribe from
this event?

Thanks in advance.


Ads