// call this whenever the
        // ManagementEventWatcher.EventArrived is fired

        protected virtual void OnWmiEventReceived(
            WmiEventReceivedEventArgs e)
        {
            if (WmiEventReceived != null)
            {
                WmiEventReceived(this, e);
            }
        }
        private void watcherEventHandler(
            object sender, EventArrivedEventArgs e)
        {
            WmiEventReceivedEventArgs ex = new WmiEventReceivedEventArgs(
                (ManagementBaseObject)e.NewEvent["TargetInstance"], null);

            OnWmiEventReceived(ex);
        }
        // Event handler procedure
        // for events received from MonitoredItem.

        public void HandleEvent(
            object sender, WmiEventReceivedEventArgs e)
        {
            richTextMutex.WaitOne();

            richEventReceiver.AppendText(
                DateTime.Now.ToLongTimeString() +
                " : Event received" + Environment.NewLine);
            richEventReceiver.AppendText(
                "Class : " + e.TargetInstance.ClassPath.ClassName +
                Environment.NewLine);
            richEventReceiver.AppendText(
                "Instance : " + Environment.NewLine + e.TargetInstance.
                SystemProperties["__RelPath"].Value.ToString() +
                Environment.NewLine);

            // TODO: Change this to only delete lines from the beginning

            if (richEventReceiver.Text.Length > 100000)
            {
                richEventReceiver.Text = "";
            }

            richEventReceiver.AppendText(Environment.NewLine);

            richTextMutex.ReleaseMutex();

            foreach (EventAction action in
                     (sender as MonitoringItem).Actions.Values)
            {
                if (action.State == EventActionState.Active)
                {
                    try
                    {
                        action.Execute(e.TargetInstance, e.PreviousInstance);
                    }
                    catch (FileNotFoundException ex)
                    {
                        if (Properties.Settings.Default.Popup_Show)
                        {
                            PopupStarter popup = new PopupStarter(
                                ex.FileName + Environment.NewLine +
                                "The script file could not be found");

                            popup.Show();
                        }
                    }
                }
            }
        }