locked
WMI Framework - EventArrived not fired RRS feed

  • Question

  • I'm having problems getting EventArrived to fire on a ManagementEventWatcher

    When I run the code it will wait on the last line until I open notepad.exe when it will continue, however, the EventArrived delegate won't get executed.  I've read about needing to 'unregister' events, but I can't find any detail on how to do this.

    Any clues on what might be causing my EventArrived to not execute?

          var wqlQuery = new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace where ProcessName='notepad.exe'");
          var watcher2 = new ManagementEventWatcher(wqlQuery);
          watcher2.EventArrived += watcher_EventArrived;
          watcher2.WaitForNextEvent();

    This post reports 'similar' problems, however for them the events fire a few times, I haven't ever got my event to fire - http://social.msdn.microsoft.com/Forums/en-US/ed03e8ad-28c3-4cf4-ae06-fe8f27adac2f/managementeventwatcher-stops-raising-eventarrived-after-running-application-several-times?forum=netfxbcl

    Wednesday, March 19, 2014 5:14 AM

Answers

  • Hello,

    The event needs us to start it firstly. So have a try change your codes to be:

    var wqlQuery = new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace where ProcessName='notepad.exe'");
    
    var watcher2 = new ManagementEventWatcher(wqlQuery);
    
    watcher2.EventArrived += watcher_EventArrived;
    
    watcher2.Start();
    
    watcher2.WaitForNextEvent();
    
    watcher2.Stop();
    

    The event then can be fired successfully:

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Thursday, March 27, 2014 7:39 AM
    Thursday, March 20, 2014 5:58 AM