N
Nenad Dobrilovic
I have an interesting issue with Open mail item's event.
I have a MailItem wrapper class, which exposes Opening event like this;
public class MailDocument
{
private Outlook.MailItem mailItem;
private static Dictionary<string, MailDocument> documents = new
Dictionary<string, MailDocument>();
public event Action<MailDocument, CancelEventArgs> Opening;
public MailDocument(Outlook.MailItem item)
{
this.mailItem = item;
((Outlook.ItemEvents_10_Event)mailItem).Open += new
Outlook.ItemEvents_10_OpenEventHandler(onOpen);
documents.Add(item.EntryID, this);
}
private void onOpen(ref bool cancel)
{
CancelEventArgs args = new CancelEventArgs(cancel);
Opening(this, args);
cancel = args.Cancel;
}
public static MailDocument Get(Outlook.MailItem mailItem)
{
MailDocument mailDocument;
documents.TryGetValue(mailItem.EntryID, out mailDocument);
return mailDocument;
}
}
}
NewInspector event handler is like this:
Outlook.MailItem current = inspector.CurrentItem as
Outlook.MailItem;
MailDocument mailDocument = MailDocument.Get(current);
mailDocument.Opening += new Action<MailDocument,
CancelEventArgs>(OnOpening);
Opening event is never invoked.
But, if I change these lines of code, event handler is invoked every time.
Outlook.MailItem current = inspector.CurrentItem as
Outlook.MailItem;
MailDocument mailDocument = new MailDocument(current);
mailDocument.Opening += new Action<MailDocument,
CancelEventArgs>(OnOpening);
Do you have an idea why this is happening? I noticed that in the default
Microsoft example is the same. Also, if I cancel a mail item default
inspector, it does shows for a part of second, so that a display is
flickering a little bit.
I have a MailItem wrapper class, which exposes Opening event like this;
public class MailDocument
{
private Outlook.MailItem mailItem;
private static Dictionary<string, MailDocument> documents = new
Dictionary<string, MailDocument>();
public event Action<MailDocument, CancelEventArgs> Opening;
public MailDocument(Outlook.MailItem item)
{
this.mailItem = item;
((Outlook.ItemEvents_10_Event)mailItem).Open += new
Outlook.ItemEvents_10_OpenEventHandler(onOpen);
documents.Add(item.EntryID, this);
}
private void onOpen(ref bool cancel)
{
CancelEventArgs args = new CancelEventArgs(cancel);
Opening(this, args);
cancel = args.Cancel;
}
public static MailDocument Get(Outlook.MailItem mailItem)
{
MailDocument mailDocument;
documents.TryGetValue(mailItem.EntryID, out mailDocument);
return mailDocument;
}
}
}
NewInspector event handler is like this:
Outlook.MailItem current = inspector.CurrentItem as
Outlook.MailItem;
MailDocument mailDocument = MailDocument.Get(current);
mailDocument.Opening += new Action<MailDocument,
CancelEventArgs>(OnOpening);
Opening event is never invoked.
But, if I change these lines of code, event handler is invoked every time.
Outlook.MailItem current = inspector.CurrentItem as
Outlook.MailItem;
MailDocument mailDocument = new MailDocument(current);
mailDocument.Opening += new Action<MailDocument,
CancelEventArgs>(OnOpening);
Do you have an idea why this is happening? I noticed that in the default
Microsoft example is the same. Also, if I cancel a mail item default
inspector, it does shows for a part of second, so that a display is
flickering a little bit.