locked
wmi event consumption problem RRS feed

  • Question

  • Hi,
    I am facing a problem while consuming wmi extrisinic events. 

    i have created a Type by decorating with InstrumentationType.event and have use this type to fire events in my application code. 

    i have also used defaultprojectmanagementinstaller and have put the runinstaller as true. although the event class could be seen in the root\cimv2, no events are consumed even though it is raised. i have put here the same code, am i doing something wrong.


    [assembly: Instrumented(@"root\CIMv2")]




    [RunInstaller(true)]
        public class myInstaller : DefaultManagementProjectInstaller
        {
        }


        [InstrumentationClass(InstrumentationType.Event)]
        public class WMIEvent1
        {
            int eventID1;
            public int EventID1
            {
                get { return this.eventID1; }
                set { this.eventID1 = value; }
            }
        }


        class Program
        {


            static void FireEvents()
            {
                while (true)
                {

                    WMIEvent1 e1 = new WMIEvent1();
                    e1.EventID1= 20;
                    Instrumentation.Fire(e1);
                    Thread.Sleep(1000);
                }
            }


            // Sample Usage
            static void Main()
            {


               
                ManagementScope scope=new ManagementScope(@"root\cimv2");
                string qryString = "select * from WMIEvent WITHIN 10";
                EventQuery qry = new EventQuery(qryString);
                
                

                Thread ts = new Thread(new ThreadStart(FireEvents));
                ts.Start();


                ManagementEventWatcher ew = new ManagementEventWatcher(scope, qry);
                while (true)
                {
                    ManagementBaseObject mo = ew.WaitForNextEvent();
                    // this line never comes up.
                    Console.WriteLine("listening for events");
             
                    
                }
            }
        }
    }


    thanks



    healthy disregard for the impossible
    • Moved by Max Wang_1983 Tuesday, April 26, 2011 5:47 PM forum consolidation (From:Architecture, Tools, and Process for ISVs)
    Sunday, March 29, 2009 3:41 PM