Group:  Microsoft Outlook » microsoft.public.outlook.program_addins
Thread: Item Unload Event Doesn't Fire

Geek News

Item Unload Event Doesn't Fire
Tim Pulley 5/11/2007 9:51:02 PM
I'm using VS 2K5, C#, VSTO SE and Outlook 2K7. I've created an Item event
handler class and hooked it up to the following events: AttachmentAdd, Save,
PropertyChange, Close and Unload. All the events fire as expected except
Unload. I've searched but I haven't found any info about a problem with this
event. I don't think I'm doing anything wrong but here's the code to hook the
Unload event just in case.

public class OLItemEventsHandler
{
protected Object m_oOLItem;
protected Outlook.ItemEvents_10_Event m_ItemEvents;
protected Outlook.ItemEvents_10_UnloadEventHandler
m_ItemEventsHandler_Unload;


public OLItemEventsHandler(object oOLItem)
{

m_oOLItem = oOLItem;

m_ItemEvents = (Outlook.ItemEvents_10_Event) oOLItem;

m_ItemEventsHandler_Unload = new
Microsoft.Office.Interop.Outlook.ItemEvents_10_UnloadEventHandler(itemEvent_Unload);

m_ItemEvents.Unload += m_ItemEventsHandler_Unload;
}


protected void itemEvent_Unload()
{
Trace.WriteLine("Item Unload Event Fired");
}

}


Re: Item Unload Event Doesn't Fire
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 5/12/2007 4:39:51 PM
Are you instantiating the item you want to handle Unload for in
Application_ItemLoad?

Unload won't necessarily fire when an item is closed, so if your handler is
going out of scope on Close you'd never get the event. It fires at some
point when Outlook unloads the item from it's in memory cache. That could be
seconds or minutes after closing the item. Items are "loaded" not only when
opening them but even by their being displayed in the reading pane.

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


"Tim Pulley" <Tim Pulley[ at ]discussions.microsoft.com> wrote in message
news:69C299CD-C4C3-4E4E-B629-8860CB3F0270[ at ]microsoft.com...
[Quoted Text]
> I'm using VS 2K5, C#, VSTO SE and Outlook 2K7. I've created an Item event
> handler class and hooked it up to the following events: AttachmentAdd,
> Save,
> PropertyChange, Close and Unload. All the events fire as expected except
> Unload. I've searched but I haven't found any info about a problem with
> this
> event. I don't think I'm doing anything wrong but here's the code to hook
> the
> Unload event just in case.
>
> public class OLItemEventsHandler
> {
> protected Object m_oOLItem;
> protected Outlook.ItemEvents_10_Event m_ItemEvents;
> protected Outlook.ItemEvents_10_UnloadEventHandler
> m_ItemEventsHandler_Unload;
>
>
> public OLItemEventsHandler(object oOLItem)
> {
>
> m_oOLItem = oOLItem;
>
> m_ItemEvents = (Outlook.ItemEvents_10_Event) oOLItem;
>
> m_ItemEventsHandler_Unload = new
> Microsoft.Office.Interop.Outlook.ItemEvents_10_UnloadEventHandler(itemEvent_Unload);
>
> m_ItemEvents.Unload += m_ItemEventsHandler_Unload;
> }
>
>
> protected void itemEvent_Unload()
> {
> Trace.WriteLine("Item Unload Event Fired");
> }
>
> }
>
>

Re: Item Unload Event Doesn't Fire
Tim Pulley 5/16/2007 3:26:00 PM
Ken,

Thanks for the reply. I've solved the problem but don't understand why it
was happening.

After testing a bit more, I noticed that the NewInspector event didn't fire
after I sent a meeting request. So I stripped my code down to just the
NewInspector event handler. After the code change the NewInspector event only
fired once, the very first time an inspector was opened. I never received
another NewInspector event after that. I was handling the event in the
ThisAddIn class so I decided to create a new class to process the event. Once
I did this everything worked as expected.

I'm new to VSTO (all my previous Outlook addin work was done with C++ & ATL)
and I haven't read all the documentation so perhaps there's something I
missed. Any thoughts about why this was a problem? Are there any known
limitations on what can be done in the ‘ThisAddIn’ class?

Tim


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

[Quoted Text]
> Are you instantiating the item you want to handle Unload for in
> Application_ItemLoad?
>
> Unload won't necessarily fire when an item is closed, so if your handler is
> going out of scope on Close you'd never get the event. It fires at some
> point when Outlook unloads the item from it's in memory cache. That could be
> seconds or minutes after closing the item. Items are "loaded" not only when
> opening them but even by their being displayed in the reading pane.
>
> --
> 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
>
>
> "Tim Pulley" <Tim Pulley[ at ]discussions.microsoft.com> wrote in message
> news:69C299CD-C4C3-4E4E-B629-8860CB3F0270[ at ]microsoft.com...
> > I'm using VS 2K5, C#, VSTO SE and Outlook 2K7. I've created an Item event
> > handler class and hooked it up to the following events: AttachmentAdd,
> > Save,
> > PropertyChange, Close and Unload. All the events fire as expected except
> > Unload. I've searched but I haven't found any info about a problem with
> > this
> > event. I don't think I'm doing anything wrong but here's the code to hook
> > the
> > Unload event just in case.
> >
> > public class OLItemEventsHandler
> > {
> > protected Object m_oOLItem;
> > protected Outlook.ItemEvents_10_Event m_ItemEvents;
> > protected Outlook.ItemEvents_10_UnloadEventHandler
> > m_ItemEventsHandler_Unload;
> >
> >
> > public OLItemEventsHandler(object oOLItem)
> > {
> >
> > m_oOLItem = oOLItem;
> >
> > m_ItemEvents = (Outlook.ItemEvents_10_Event) oOLItem;
> >
> > m_ItemEventsHandler_Unload = new
> > Microsoft.Office.Interop.Outlook.ItemEvents_10_UnloadEventHandler(itemEvent_Unload);
> >
> > m_ItemEvents.Unload += m_ItemEventsHandler_Unload;
> > }
> >
> >
> > protected void itemEvent_Unload()
> > {
> > Trace.WriteLine("Item Unload Event Fired");
> > }
> >
> > }
> >
> >
>
>
Re: Item Unload Event Doesn't Fire
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 5/16/2007 3:42:51 PM
Was the inspectors object used for the NewInspector event declared at a
level that it won't go out of scope?

I usually declare a class level object for Inspectors in ThisAddIn and add
the event handler for NewInspector there. I use separate Inspector class
wrappers that are stored in a List or SortedList to keep the Inspector
classes alive. Inside each wrapper class I handle whatever events I'm
interested in for the Inspector and its CurrentItem (like a mail or
appointment item).

I do handle NewInspector and NewExplorer in ThisAddIn, but again those
objects are declared at the class (module) level.

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


"Tim Pulley" <TimPulley[ at ]discussions.microsoft.com> wrote in message
news:7C99EBDE-744C-48DE-B726-2FE9026C2A86[ at ]microsoft.com...
[Quoted Text]
> Ken,
>
> Thanks for the reply. I've solved the problem but don't understand why it
> was happening.
>
> After testing a bit more, I noticed that the NewInspector event didn't
> fire
> after I sent a meeting request. So I stripped my code down to just the
> NewInspector event handler. After the code change the NewInspector event
> only
> fired once, the very first time an inspector was opened. I never received
> another NewInspector event after that. I was handling the event in the
> ThisAddIn class so I decided to create a new class to process the event.
> Once
> I did this everything worked as expected.
>
> I'm new to VSTO (all my previous Outlook addin work was done with C++ &
> ATL)
> and I haven't read all the documentation so perhaps there's something I
> missed. Any thoughts about why this was a problem? Are there any known
> limitations on what can be done in the ‘ThisAddIn’ class?
>
> Tim

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net