View Single Post
  #1  
Old September 10th 08, 02:09 PM posted to microsoft.public.outlook.program_addins
Abhi.[_2_]
external usenet poster
 
Posts: 3
Default About Outlook addin events


Hello Ken,
Thanks for your reply.
I am using VS 2005 C# Office Outlook add-in for Outlook 2003. My code is
like,

public partial class ThisApplication
{

Microsoft.Office.Interop.Outlook.MAPIFolder fldCalendar = null;
Microsoft.Office.Interop.Outlook._Application outlookObj = new
Microsoft.Office.Interop.Outlook.Application();

private void ThisApplication_Startup(object sender, System.EventArgs e)
{
fldCalendar =
(Microsoft.Office.Interop.Outlook.MAPIFolder)outlo okObj.Session.GetDefaultFolder(Microsoft.Office.In terop.Outlook.OlDefaultFolders.olFolderCalendar);
fldCalendar.Items.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(Items_ItemChange);
fldCalendar.Items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(Items_ItemAdd);
fldCalendar.Items.ItemRemove += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemR emoveEventHandler(Items_ItemRemove);


}


private void Items_ItemAdd(object Item)
{
}

private void Items_ItemChange(object Item)
{
}

private void Items_ItemRemove()
{
}

private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisApplication_Startup);
this.Shutdown += new
System.EventHandler(ThisApplication_Shutdown);
}
}
even I tried with,

private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisApplication_Startup);
this.Shutdown += new
System.EventHandler(ThisApplication_Shutdown);

((Microsoft.Office.Interop.Outlook.MAPIFolder)outl ookObj.Session.GetDefaultFolder(Microsoft.Office.I nterop.Outlook.OlDefaultFolders.olFolderCalendar)) .Items.ItemAdd
+= new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(Items_ItemAdd);

((Microsoft.Office.Interop.Outlook.MAPIFolder)outl ookObj.Session.GetDefaultFolder(Microsoft.Office.I nterop.Outlook.OlDefaultFolders.olFolderCalendar)) .Items.ItemChange
+= new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(Items_ItemChange);

((Microsoft.Office.Interop.Outlook.MAPIFolder)outl ookObj.Session.GetDefaultFolder(Microsoft.Office.I nterop.Outlook.OlDefaultFolders.olFolderCalendar)) .Items.ItemRemove
+=new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemR emoveEventHandler(Items_ItemRemove);
}

So where should I add event handler now in order to avoid from being garbage
collected ?
Any other way to do this?
Thanks.

Abhi


"Ken Slovak - [MVP - Outlook]" wrote:

Your event handlers are most likely being garbage collected. Declare class
level objects that will keep scope as long as your code is running and
attach the event handlers to those objects.

At class level:

Outlook.Items _items;

After instantiating _items as the Calendar.Items collection then add your
event handler.

When you post here please post the Outlook version and what language and
development platform you're using so people have sufficient information to
help.

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


"Abhi." wrote in message
...

I have problem in Outlook addin events this events just do occur
for first time only means once Item_Add event gets fired then after that
no
event fires I think some where the events are washed out.
I have tried in InternalStartup() and as well in ThisApplication_Startup()
like , ldCalendar.Items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(Items_ItemAdd);
All is working fine but due to events problem I am not getting to the
solution.
I think, somewhere Events should be raised from where should not
washed out. Should I do some extra for it ?

Thanks.




Ads