Anytime I invoke MessageBox.Show() or [custom form].Show() or [custom form].ShowDialog(), the ThisAddIn.Application.Inspectors.NewInspector event no longer fires. Is there any easy fix
9/5/2007:
This is a general problem that can be easily reproduced in several different ways but I'll include a simple example.
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
MessageBox.Show("howdy");
Application.Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
private void Inspectors_NewInspector(Outlook.Inspector Inspector)
{
if (Inspector.CurrentItem is Outlook.MailItem)
{
Outlook.MailItem mail = (Outlook.MailItem)Inspector.CurrentItem;
mail.Subject = "new subject";
}
}
}
If the MessageBox.Show("howdy") line is commented out, any message that opens up gets "new subject" as the subject. If the message box is allowed to display, Inspectors_NewInspector is never invoked. The same is true if a custom form is shown in place of the message box. If the code to show a message box or form is within the Inspectors_NewInspector method, the message box or form will be shown once (Inspectors_NewInspector will be invoked once) but the next time an item is opened, Inspectors_NewInspector is not invoked.