I add an event handler to every AppointmentItem‘s send event. This event handler just do some logging thing. I create a meeting through Outlook 2003, and then update the meeting twice. At last I check the log.
this.Application.Inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(_inspectors_NewInspector);
private void _inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector inspector)
{
if(inspector.CurrentItem is Outlook.AppointmentItem)
{
_appointmentEvent = inspector.CurrentItem as Outlook.ItemEvents_10_Event;
_appointmentEvent.Send += new Microsoft.Office.Interop.Outlook.ItemEvents_10_SendEventHandler(_appointmentEvent_Send);
}
}
private void _appointmentEvent_Send(ref bool Cancel)
{
Log.WriteLog("InspectorWrapper: _appointmentEvent_Send Enter");
Log.WriteLog("InspectorWrapper: _appointmentEvent_Send Exit");
}
I check the log. I found that send event handler will be called many times.
2012-05-16 10:07:21:066: InspectorWrapper: _appointmentEvent_Send Enter
2012-05-16 10:07:21:067: InspectorWrapper: _appointmentEvent_Send Exit
…
2012-05-16 10:07:27:281: InspectorWrapper: _appointmentEvent_Send Enter
2012-05-16 10:07:27:283: InspectorWrapper: _appointmentEvent_Send Exit
2012-05-16 10:07:27:283: InspectorWrapper: _appointmentEvent_Send Enter
2012-05-16 10:07:27:284: InspectorWrapper: _appointmentEvent_Send Exit
…
2012-05-16 10:07:32:607: InspectorWrapper: _appointmentEvent_Send Enter
2012-05-16 10:07:32:608: InspectorWrapper: _appointmentEvent_Send Exit
2012-05-16 10:07:32:609: InspectorWrapper: _appointmentEvent_Send Enter
2012-05-16 10:07:32:609: InspectorWrapper: _appointmentEvent_Send Exit
2012-05-16 10:07:32:610: InspectorWrapper: _appointmentEvent_Send Enter
2012-05-16 10:07:32:610: InspectorWrapper: _appointmentEvent_Send Exit
Why?
You should add logging to the
NewInspectorevent to see how many times you latch onto theAppointmentItem.Sendevent. My assumption is thatNewInspectoris your issue. It is best practice to manage a list of active inspectors using a customInspectorWrapperas a container to avoid multiple event latching.For reference, take a look at
FindOutlookInspectorfrom this MSDN reference.