A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

About Outlook addin events



 
 
Thread Tools Search this Thread Display Modes
  #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.




  #2  
Old September 10th 08, 03:23 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default About Outlook addin events

As I said, add an Items collection object at class level. Also, it's not
good practice to use a lot of dot operators as you're doing. .NET creates
internal object variables for each level of dot operator and you have no
control over those, when they go out of scope or if they create memory
leaks.

You also should be using the Outlook.Application object passed to you by
VSTO and not instantiating a new Outlook.Application object. The one passed
by VSTO is trusted, the one you create isn't trusted.

I'd really suggest that you download the sample VSTO Outlook addins from the
Office development Web site at MS to see the basics of how to do things and
what some of the best practices are.

What you need to do is something like this:

using Outlook = Microsoft.Office.Interop.Outlook;

public partial class ThisApplication
{

Outlook.MAPIFolder fldCalendar = null;

Outlook._Application outlookObj = null;

Outlook.Items _items = null;

private void ThisApplication_Startup(object sender, System.EventArgs e)
{
outlookObj = this;

Outlook.NameSpace ns = outlookObj.GetNameSpace("MAPI);

fldCalendar =
ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFol derCalendar);

_items = (Outlook.Items)fldCalendar.Items;

_items.ItemChange += new
Outlook.ItemsEvents_ItemChangeEventHandler(Items_I temChange);

And so on.

That "_items" collection will remain in scope as long as your addin is
running and won't get garbage collected. You also see how I declare and use
separate Outlook objects instead of using multiple dot operators.

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

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


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New Vew in outlook as addin madhur Add-ins for Outlook 2 May 27th 08 06:40 PM
"Recurring events" glitch when categorzing events in Outlook Cal 2 dwarfdog Outlook - Calandaring 1 November 29th 07 10:55 PM
Outlook Addin Martin Outlook and VBA 1 May 17th 07 03:29 PM
single events change to recurring events without a prompt. TPDavidson Outlook - Calandaring 0 February 12th 07 05:48 AM
Item open events and double click events in exchange client extension. Fanxa Add-ins for Outlook 1 August 9th 06 09:18 AM


All times are GMT +1. The time now is 11:40 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.