> Unless the class is static you need to call new on it to initialize it
> correctly.
>
> --
> Ken Slovak
> [MVP - Outlook]
>
http://www.slovaktech.com> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
>
http://www.slovaktech.com/products.htm>
>
> "Nenad Dobrilovic" <NenadDobrilovic[ at ]discussions.microsoft.com> wrote in
> message news:47393D7F-DA2B-4D0B-B1DA-43ABBD65EAD7[ at ]microsoft.com...
> >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.
> > --
> > Nenad Dobrilovic
>
>