Maybe this is a dumb question, but do event listeners use CPU cycles like a timer, or are they inactive until the event is fired?
Is it language specific, or do all languages handle this basically the same?
I want to write a tiny service that only does anything when a network disconnect event is fired, and I don't want the service to use up resources just listening (other than memory of course).
I plan to do something like this
using NetworkUtilities;
ManagementEventWatcher networkAdapterArrivalWatcher = new ManagementEventWatcher("\\root\\wmi","SELECT * FROM MSNdis_NotifyAdapterArrival ");
networkAdapterArrivalWatcher.Options.Timeout = new TimeSpan(0,0,5);
ManagementEventWatcher networkAdapterRemovalWatcher = new ManagementEventWatcher("\\root\\wmi","SELECT * FROM MSNdis_NotifyAdapterRemoval " );
networkAdapterRemovalWatcher.Options.Timeout = new TimeSpan(0,0,5);
ConnectionNotifierHandler handler = new ConnectionNotifierHandler();
networkAdapterArrivalWatcher.EventArrived += new EventArrivedEventHandler(handler.Arrived);
networkAdapterRemovalWatcher.EventArrived += new EventArrivedEventHandler(handler.Removed);
//Start watching for events
networkAdapterArrivalWatcher.Start();
networkAdapterRemovalWatcher.Start();
public void Arrived(object sender, EventArrivedEventArgs e)
{
using (ManagementBaseObject ev = e.NewEvent)
{
//Log the event
}
}
public void Removed(object sender, EventArrivedEventArgs e)
{
using (ManagementBaseObject ev = e.NewEvent)
{
//Log the event
}
}