I want to be notified when a PnP device is added or removed. To accomplish
this task, I added two occurrences of a
System.Manageme nt.ManagementEv entWatcher. I've included a snippet of code
that is called when the user pushes a button to start listening. Using the
Windows Task manager I can monitor the CPU usage. When the watchers are
active, the CPU usage spikes to 100%. Turning of the watchers reduces the
CPU usage back to it's quiescent state. Is this expected behavior, or am I
doing something incorrectly? Is there a better way to monitor for PnP
devices being added or removed without incurring this CPU overhead?
TIA
Brad
Code example:
Public Sub StartListen()
Newwatcher = New System.Manageme nt.ManagementEv entWatcher
Newwatcher.Quer y = New System.Manageme nt.EventQuery(" SELECT * FROM
__InstanceCreat ionEvent WITHIN 1 WHERE TargetInstance ISA
'Win32_PnPEntit y'")
AddHandler Newwatcher.Even tArrived, AddressOf NewPlugPlay
Newwatcher.Star t()
Removewatcher = New System.Manageme nt.ManagementEv entWatcher
Removewatcher.Q uery = New System.Manageme nt.EventQuery(" SELECT * FROM
__InstanceDelet ionEvent WITHIN 1 WHERE TargetInstance ISA
'Win32_PnPEntit y'")
AddHandler Removewatcher.E ventArrived, AddressOf RemovedPlugPlay
Removewatcher.S tart()
End Sub