M
Mustafa
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
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