Re: Removing The registered Event Handlers
- From: "Ken Slovak - [MVP - Outlook]" <kenslovak@xxxxxxxx>
- Date: Thu, 7 Aug 2008 09:27:08 -0400
Try setting both the Tasks and event to null and then call Marshal.ReleaseComObject on both. See if that helps.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
"Mustafa" <mustafa.faisan@xxxxxxxxx> wrote in message news:e2b194f1-45d4-4bbd-a825-f97a7c79fffb@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi all,
I am writing a Outlook Add-in which subscribes to the Event in
Outlook, I am registering an Event Handler for Task Folder (See code
Below), But later I want to Remove this Handler from Task Folder so
that this function is not Executed. But the Removing the Event Handler
is not Working, the event is getting fired even after removing the
Event Handler, I appreciate any Help and Suggestions
class test
{
Outlook.Application App = null;
Outlook.NameSpace Ns = null;
Outlook.MAPIFolder Tasks = null;
Outlook.ItemsEvents_ItemAddEventHandler ItemAdd = null;
Outlook.TaskItem FirstTask = null;
private void Initialize_Outlook()
{
try
{
App = new Outlook.Application();
Ns = App.GetNamespace("MAPI");
Tasks =
Ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
// Register Event Handler
Tasks.Items.ItemAdd += new
Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
// Remove Event Handler
Tasks.Items.ItemAdd -= new
Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
}
catch (Exception Ex)
{
MessageBox.Show("Outlook Exception : " + Ex.Message);
}
finally
{
}
}
void Items_ItemAdd(object Item)
{
try
{
MessageBox.Show("From Task Add
event");
}
catch (Exception Ex)
{
}
finally
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(Item);
}
}
}
In the Above Code the Items_ItemAdd is firing ...
Regards
Mohamed Mustafa
.
- Follow-Ups:
- Re: Removing The registered Event Handlers
- From: Mustafa
- Re: Removing The registered Event Handlers
- References:
- Removing The registered Event Handlers
- From: Mustafa
- Removing The registered Event Handlers
- Prev by Date: Removing The registered Event Handlers
- Next by Date: Re: Basic Outlook 2007 question - how do I know if invitations wer
- Previous by thread: Removing The registered Event Handlers
- Next by thread: Re: Removing The registered Event Handlers
- Index(es):
Relevant Pages
|