This may be a dumb question, but do event listeners use processor cycles such as a timer, or are they inactive until the event fires?
Is it language specific or are all languages processed basically the same?
I want to write a tiny service that does something only when a network disconnect event is disabled, and I do not want the service to use resources only for listening (except for 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);
networkAdapterArrivalWatcher.Start();
networkAdapterRemovalWatcher.Start();
public void Arrived(object sender, EventArrivedEventArgs e)
{
using (ManagementBaseObject ev = e.NewEvent)
{
}
}
public void Removed(object sender, EventArrivedEventArgs e)
{
using (ManagementBaseObject ev = e.NewEvent)
{
}
}
source
share