B
Brad Markisohn
I want to be notified when a PnP device is added or removed. To accomplish
this task, I added two occurrences of a
System.Management.ManagementEventWatcher. 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.Management.ManagementEventWatcher
Newwatcher.Query = New System.Management.EventQuery("SELECT * FROM
__InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA
'Win32_PnPEntity'")
AddHandler Newwatcher.EventArrived, AddressOf NewPlugPlay
Newwatcher.Start()
Removewatcher = New System.Management.ManagementEventWatcher
Removewatcher.Query = New System.Management.EventQuery("SELECT * FROM
__InstanceDeletionEvent WITHIN 1 WHERE TargetInstance ISA
'Win32_PnPEntity'")
AddHandler Removewatcher.EventArrived, AddressOf RemovedPlugPlay
Removewatcher.Start()
End Sub
this task, I added two occurrences of a
System.Management.ManagementEventWatcher. 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.Management.ManagementEventWatcher
Newwatcher.Query = New System.Management.EventQuery("SELECT * FROM
__InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA
'Win32_PnPEntity'")
AddHandler Newwatcher.EventArrived, AddressOf NewPlugPlay
Newwatcher.Start()
Removewatcher = New System.Management.ManagementEventWatcher
Removewatcher.Query = New System.Management.EventQuery("SELECT * FROM
__InstanceDeletionEvent WITHIN 1 WHERE TargetInstance ISA
'Win32_PnPEntity'")
AddHandler Removewatcher.EventArrived, AddressOf RemovedPlugPlay
Removewatcher.Start()
End Sub