I don't write C# but I can tell you that you'll need to instantiate an explicit Inspectors collection at the module level in order to subscribe to its NewInspector event without the garbage collector releasing the objects before NewInspector ever fires. In other words, you can't use this.Inspectors.NewInspector. You need an explicit Inspectors object.

Signature
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
> In the following C# code, I can debug and see all the startup code is called
> setting the NewInspectorEvent but when I open a contact, the
[quoted text clipped - 33 lines]
> }
> }
va - 17 Feb 2006 16:57 GMT
Sue,
I thought the "this.Inspectors" is the application object's "default"
collection which is instantiated whenever/wherever the application object was
instantiated. So that all I need to do is add a delegate to its events.
If I create my own "global" (module level) inspector object, do I set the
"this.Inspectors" to that new Inspector object?
Sue Mosher [MVP-Outlook] - 17 Feb 2006 18:48 GMT
There's a discussion at http://www.pcreview.co.uk/forums/thread-1855913.php that deals with the issue I was thinking of, that because Items is a temporary implied object, it can't fire events forever.

Signature
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
> Sue,
>
[quoted text clipped - 4 lines]
> If I create my own "global" (module level) inspector object, do I set the
> "this.Inspectors" to that new Inspector object?
va - 17 Feb 2006 19:18 GMT
Sue,
Two interesting finds (one solution and the other a bug!):
1) You were right - interestingly enough - I just needed a global reference
as you suggested. I would think the GC would not clean up a significant
object in the main application. Very oddd.... Here is the code FYI:
private Outlook.Inspectors _insptrs;
public void ThisApplication_Startup(object sender, System.EventArgs e)
{
_insptrs = this.Inspectors;
_insptrs.NewInspector += new
Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(NewInspectorEvent);
}
2) The bug is in the NewInspectorEvent handler. When I examine the Inspector
passed to the handler the CurrentItem variable only states it is a
"System.__ComObject" - not "IPM.Contact" or "IPM.Note" etc. Below is teh
WatchWindow detials. The inspector.Caption has a title like "untitled -
Contact" or "Untitles - Message" but that is risky. What If I only want my
special type "IPM.Contact"?
Here is the Watch Window details for Contact
- CurrentItem {System.__ComObject} object {System.__ComObject}
- base {System.__ComObject} System.MarshalByRefObject {System.__ComObject}
- Non-Public members
- [System.__ComObject] {System.__ComObject} System.__ComObject
- base {System.__ComObject} System.MarshalByRefObject {System.__ComObject}
__identity null object
Identity null object
m_ObjectToDataMap null System.Collections.Hashtable
__identity null object
Identity null object
Sue Mosher [MVP-Outlook] - 17 Feb 2006 20:59 GMT
Helmut's partial sample at http://www.outlookcode.com/codedetail.aspx?id=856 does it like this:
private void myInspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
try
{
object Item = Inspector.CurrentItem;
// Check the ItemsType
if (Item is OL.MailItem)
{
// Create a new Item wrapper Object
XMailItem myMail = new XMailItem (Item);
// Register for the Item Close event
myMail.Item_Closed +=new XEventHandler(myMail_Item_Closed);
// remember the Item in Collection
myActiveItems.Add (myMail.HashCode,myMail);
}
}
catch (System.Exception ex)
{
MessageBox.Show (ex.Message);
}
}

Signature
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
> Sue,
>
[quoted text clipped - 33 lines]
> __identity null object
> Identity null object