CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Jun 2010
    Location
    .net 2.0 3.0 3.5 4.0 VS 2005, VSE 2010
    Posts
    4

    Question newbie question about Event Watchers

    I'm trying to learn .net without learning C# first (not my choice) and I just ran across this code:

    Code:
     watcher.EventArrived += new EventArrivedEventHandler(handler.Arrived);
    The full source code is below. I don't really get this line, though, and MSDN says nothing about it, does the += mean it's added on a queue (the handler.Arrived event)? I don't need this explained in plain english but if someone could explain that line in C or C++ terms I'd be very grateful, thanks.

    sscout

    Code:
     using System;
    using System.Management;
    public class EventWatcher
    {
        public static void Main(string[] args)
        {
            // Create event query to be notified within 1 second of
            // a change in a service
            WqlEventQuery query = new WqlEventQuery("__InstanceCreationEvent"
                , new TimeSpan(0, 0, 1), "TargetInstance isa \"Win32_Process\"");
            // Initialize an event watcher and subscribe to events
            // that match this query
            ManagementEventWatcher watcher = new ManagementEventWatcher(query);
            MyHandler handler = new MyHandler();
            watcher.EventArrived += new EventArrivedEventHandler(handler.Arrived);
            watcher.Start();
            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();
        }
        public class MyHandler
        {
            public void Arrived(object sender, EventArrivedEventArgs e)
            {
                Console.WriteLine("Process {0} has created, path is: {1}"
            , ((ManagementBaseObject)(e.NewEvent["TargetInstance"]))["Name"]
                , ((ManagementBaseObject)(e.NewEvent["TargetInstance"]))["ExecutablePath"]);
            }
        }
    }
    Last edited by sscout; June 8th, 2010 at 04:07 PM. Reason: readability

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured