View Single Post
  #6  
Old May 4th 07, 05:29 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default VSTO Com-add in prevents Outlook Notes from closing first time

I wouldn't release anything at all in NewInspector, it's just not needed and
probably will cause problems. I use late binding to get the Class of the
Inspector.CurrentItem using code like this:

object item = Inspector.CurrentItem;
Type _type;
_type = item.GetType();
object[] args = new Object[] { };
Outlook.OlObjectClass _class;

_class = (Outlook.OlObjectClass)_type.InvokeMember("Class",
BindingFlags.Public | BindingFlags.GetField | BindingFlags.GetProperty,
null, item, _args);

That lets me check the item.Class. If it's a type I want to handle I do so,
if not the NewInspector code does nothing else. It releases nothing. I don't
even release item, all that I do is surround the tests for Class in
try{}...catch{} blocks.

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


"PShah" wrote in message
oups.com...
Ken

So here is the code in the inspectors_NewInspector method (which is
wired up in the ThisApplication_Startup)


private void inspectors_NewInspector(Outlook.Inspector inspector)
{
try
{
Object objCurrentItem = inspector.CurrentItem;
if (objCurrentItem is Outlook.MailItem)
{
// Enters this if loop if the item is Mail Item and my
complete logic is here since my plugin
// only has programming done for MailItems
}
else
{
Marshal.ReleaseComObject (objCurrentItem);
objCurrentItem = null;

GC.WaitForPendingFinalizers( );
GC.Collect( );
}
}
catch (Exception ex)
{
// Logging to local Event Logs
}
}

So Ken - as you see from above code - everything which is not an
MailItem falls into the else block (calender items, notes) etc.

I Dont do any programming for notes and totally agree with you that
they are brain-dead.

But with the above code - any item which is not MailItem falls into
the else loop (notes, calender, tasks) and even though I am cleaning
up - apparently the notes still holds a reference for inspector and so
when I click on "x" - it does close the note. When i click multiple
times on the "x" it sometimes closes the note or even crashes Outlook

What are your thoughts....

Thanks


Ads