Wrapper class cycles through all open emails when trying to send

I have use the enclosed wrapper class and have succesfully hooked the attachment and detachment events. When I hook up the send event, it behaves oddly.If I open 3 new emails, and send on any of them, the send handler fires for each open email. I can see this as the Guid on each rmail inspector can be seen when debugging. I need to keep the event handler in the wrapper so that I can read the Id which I use to retrive information from the AttachmentCount dictionary in ThisAddIn.cs. InspectorWrapper.cs Can anyone see why it would fire for each inspector, the attachments do not fire for each attachment.
using System;
using System.Collections.Generic;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;
using System.Collections;
namespace OutlookGuard
{
    public partial class ThisAddIn
    {

        public bool IsLicensed = true;
        public string Licensor = "";
        public string ExpireDate = "";



   
        /// <summary>
        /// Holds a reference to the Application.Inspectors collection
        /// Required to get notifications for NewInspector events.
        /// </summary>
        private Outlook.Inspectors _inspectors;

        /// <summary>
        /// A dictionary that holds a reference to the Inspectors handled by the add-in
        /// </summary>
        private Dictionary<Guid, InspectorWrapper> _wrappedInspectors;
        public Dictionary<Guid, int> AttachmentCount;

        
         

        /// <summary>
        /// Startup method is called when the add-in is loaded by Outlook
        /// </summary>
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {


            #region license check

            if (Properties.Settings.Default.Licence != "")
            {
                olicense myLicence = new olicense();
                oOutlookUtilities mysender = new oOutlookUtilities();

                myLicence.AccountEMail = Convert.ToString(mysender.getSenderAddress()[0]);
                myLicence.key = Properties.Settings.Default.Licence;
                myLicence.decodeLicense();
                if (myLicence.Error != "")
                {
                    MessageBox.Show("There was an error starting OutlookGuard: " + myLicence.Error);
                    IsLicensed = false;
                }
                else
                {
                    Licensor = myLicence.UserName;
                    if (myLicence.warningdays > 370) { ExpireDate = "Perpetual"; }
                    if (myLicence.warningdays < 370) { ExpireDate = Convert.ToString(myLicence.ExpiresDate).Split(' ')[0]; }

                }

                myLicence = null;
                mysender = null;
            }
            else
            {
                MessageBox.Show("This product is unregistered. Please go to the OutlookGuard website to obtain a license key, and enter the key in the settings area.");

            }

            #endregion


            _wrappedInspectors = new Dictionary<Guid, InspectorWrapper>();
            AttachmentCount = new Dictionary<Guid, int>();

            _inspectors = Globals.ThisAddIn.Application.Inspectors;
            _inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(WrapInspector);
            


            // Handle also already existing Inspectors
            // (e.g. Double clicking a .msg file)
            foreach (Outlook.Inspector inspector in _inspectors)
            {
                WrapInspector(inspector);
            }
        }

        /// <summary>
        /// Wraps an Inspector if required and remember it in memory to get events of the wrapped Inspector
        /// </summary>
        /// <param name="inspector">The Outlook Inspector instance</param>
        void WrapInspector(Outlook.Inspector inspector)
        {
            InspectorWrapper wrapper = InspectorWrapper.GetWrapperFor(inspector);
            if (wrapper != null)
            {
                // register for the closed event
                wrapper.Closed += new InspectorWrapperClosedEventHandler(wrapper_Closed);
                // remember the inspector in memory
                _wrappedInspectors[wrapper.Id] = wrapper;
                AttachmentCount[wrapper.Id] = 0;

            }
        }

        /// <summary>
        /// Method is called when an inspector has been closed
        /// Removes reference from memory
        /// </summary>
        /// <param name="id">The unique id of the closed inspector</param>
        void wrapper_Closed(Guid id)
        {
            _wrappedInspectors.Remove(id);
            AttachmentCount.Remove(id);
        }

        /// <summary>
        /// Shutdown method is called when Outlook is unloading the add-in
        /// </summary>
        /// 







        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            // do the homework and cleanup
            _wrappedInspectors.Clear();
            AttachmentCount.Clear();
            _inspectors.NewInspector -= new Outlook.InspectorsEvents_NewInspectorEventHandler(WrapInspector);
            _inspectors = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}

Open in new window

MailItemWrapper.cs
spanoutAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

spanoutAuthor Commented:
What I want to use is this:

Item.Send += new Outlook.ApplicationEvents_11_ItemSendEventHandler(gp2_fnItemSend);

But send is a method not event, how can I do this?
0
spanoutAuthor Commented:
I have fixed it:

            ((Outlook.ItemEvents_10_Event)Item).Send += new Outlook.ItemEvents_10_SendEventHandler(gp2_fnItemSend);

POinting to
void gp2_fnItemSend(ref bool cancel)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.