Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / VS Tools for Office / February 2006

Tip: Looking for answers? Try searching our database.

NewInspectorEvent won't fire

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
va - 17 Feb 2006 02:27 GMT
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  
NewInspectorEvent is never called?  Any reason this would happen?

       private void NewInspectorEvent(Outlook.Inspector inspector)
       {
           if (inspector.CurrentItem == "IPM.Contact")
               MessageBox.Show("Contact opened");

           //throw new Exception("The method or operation is not
implemented.");
       }

       private void ThisApplication_Startup(object sender, System.EventArgs
e)
       {
           this.Inspectors.NewInspector += new
Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(NewInspectorEvent);
       
       }

       #region VSTO generated code

       /// <summary>
       /// Required method for Designer support - do not modify
       /// the contents of this method with the code editor.
       /// </summary>
       private void InternalStartup()
       {
           this.Startup += new System.EventHandler(ThisApplication_Startup);
           this.Shutdown += new
System.EventHandler(ThisApplication_Shutdown);
       }

       #endregion
   }
}
Sue Mosher [MVP-Outlook] - 17 Feb 2006 12:58 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.