locked
Outlook 2007 Add-in Stabilization Issue RRS feed

  • Question

  • Hi,

    I'm trying to create an Outlook Add-in. I'm working on VS2010 and developing the add-in for Outlook 2007.

    Here is my startup function:

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.ItemLoad += new Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad);
            }

    And the working parts of the code:

            void Application_ItemLoad(object Item)
            {
                MessageBox.Show("ItemLoad Working");
    
                if(Item is Outlook.AppointmentItem) 
                this.Application.Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
            }
    
            void Inspectors_NewInspector(Outlook.Inspector Inspector)
            {
                MessageBox.Show("NewInspector Working");
                Outlook.AppointmentItem ai = Inspector.CurrentItem;
                ai.Write += new Outlook.ItemEvents_10_WriteEventHandler(ai_Write);
            }
    
            void ai_Write(ref bool Cancel)
            {
                MessageBox.Show("ai_Write Working");
            }

    I think that the problem is on the NewInspector eventHandler. Because the Inspectors_NewInspector function sometimes doesn't work, sometimes works one time(as I want), sometime works several times (two, three, four, even twelve times). And there is no working times pattern. It's quite ramdomly. How can I stabilize it?

    Monday, May 21, 2012 6:53 AM

All replies

  • because there are some problems with your code:

    1. You have to store somewhere instance of object to which you attach your event handlers (here: Inspectors), best place would be a field in class that is never out of scope, for example your Addin class

    2. you always attach new event handler on each item_load event - do it once in add-in startup, otherwise you will get as many callbacks as many times you attached to specific event

    Monday, May 21, 2012 8:03 AM
  • In addition, an item can be loaded but not opened. It will be loaded when read in the reading pane for example, but that won't fire NewInspector().
     
    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "DamianD" <=?utf-8?B?RGFtaWFuRA==?=> wrote in message news:49338041-810a-4858-a5c9-b69b3cbf4e43...

    because there are some problems with your code:

    1. You have to store somewhere instance of object to which you attach your event handlers (here: Inspectors), best place would be a field in class that is never out of scope, for example your Addin class

    2. you always attach new event handler on each item_load event - do it once in add-in startup, otherwise you will get as many callbacks as many times you attached to specific event


    Ken Slovak MVP - Outlook
    Monday, May 21, 2012 1:27 PM
  • I did it but it didn't work either. So I made the control by using flags. But thanks for your interest.
    Tuesday, May 22, 2012 10:39 AM