1
votes

I'm creating an Outlook addin that needs to trigger when the attendees of a meeting are changed. The problem I'm encountering is that the PropertyChange event of an Appointment item is firing way too much and because of that I can't get the exact amount of attendees.

Here is some of the code I'm using:

private Outlook.AppointmentItem appointmentItem;
private void Inspectors_NewInspector(Outlook.Inspector inspector)
    {
        var item = inspector.CurrentItem as Outlook.AppointmentItem;
        if (item != null)
        {
            appointmentItem = item;
            temp = inspector;
            visible = false;
            appointmentItem.PropertyChange += AppOnPropertyChange;
        }
    }

private void AppOnPropertyChange(string name)
    {

        if (name.Equals("RequiredAttendees"))
        {
            var test = appointmentItem.Recipients.Count;
        }
    }

The event is triggered way too many times, and thus "test" will get values between 1 (the sender is always an attendee) and the number of attendees. Also if you have lets say 3 attendees and you remove one, "test" will be 4 - 3 - 2 - 1.

Is there a way to figure out the exact number of attendees in an AppointmentItem?

Any help would be much appreciated.

2

2 Answers

4
votes

ItemChange("RequiredAttendees") will fire for any change in the required, optional, or resource attendees, there is nothing you an do about that.

I had luck using a timer - when ItemChange event fires, enable the timer (you can set its interval to, say, 100 ms). When the timer event fires, disable the timer (so it won't fire again). and process the recipients collection. By that time all the changes will be processed and you will only process the attendees once.

Since you are using .Net, use the Timer class from the Forms namespace (it works on the main thread) instead of the System namespace (it uses a background thread, which is a bad practice when working with Outlook objects in a COM addin).

2
votes

The PropertyChange event is fired when an explicit built-in property of the parent object is changed. Make sure that you unsubscribe from the event when the inspector window is closed or you open a new inspector window. Is that the case?

The Developing an Inspector Wrapper for Outlook 2010 discusses a technique to implement an inspector wrapper. An inspector wrapper handles multiple instances of Microsoft Outlook inspector windows.

You may also find the ItemChange event of the Items class helpful. It is fired when an item in the specified collection is changed.