|
-
June 8th, 2010, 10:02 AM
#1
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|