473,378 Members | 1,280 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Very high memory usage?

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
Nov 20 '05 #1
4 3636
Hi Brad,

Based on my understanding, when you enable the ManagementEventWatcher the
CPU will spike to 100%, it will not reduce until you stop the
ManagementEventWatcher .

Based on my test, I can not reproduce the problem.
Here goes my test code.

Dim watcher As System.Management.ManagementEventWatcher
Public Sub NewPlugPlay(ByVal sender As Object, ByVal e As
EventArrivedEventArgs)
MsgBox("New Plug and Play = " +
(CType(e.NewEvent("TargetInstance"), ManagementBaseObject))("Caption"))
End Sub
Public Sub StartListen()
watcher = New System.Management.ManagementEventWatcher
'
' managementEventWatcher1
'
watcher.Query = New System.Management.EventQuery("SELECT * FROM
__InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA
""Win32_PnPEntity""")
AddHandler watcher.EventArrived, AddressOf NewPlugPlay
watcher.Start()
End Sub
Public Sub StopListen()
watcher.Stop()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
StartListen()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
StopListen()
End Sub

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #2
Peter,

I guess that I'll have to live with CPU usage of 100% while monitoring PnP
device activity. I'm curious about the query:

SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA
""Win32_PnPEntity"""

Can you point me to a source that describes how this query, and others like
it, are created? This is not intuitive and I would've struggled without the
MSDN examples.

Thanks

Brad

"Peter Huang" <v-******@online.microsoft.com> wrote in message
news:Eb**************@cpmsftngxa07.phx.gbl...
Hi Brad,

Based on my understanding, when you enable the ManagementEventWatcher the
CPU will spike to 100%, it will not reduce until you stop the
ManagementEventWatcher .

Based on my test, I can not reproduce the problem.
Here goes my test code.

Dim watcher As System.Management.ManagementEventWatcher
Public Sub NewPlugPlay(ByVal sender As Object, ByVal e As
EventArrivedEventArgs)
MsgBox("New Plug and Play = " +
(CType(e.NewEvent("TargetInstance"), ManagementBaseObject))("Caption"))
End Sub
Public Sub StartListen()
watcher = New System.Management.ManagementEventWatcher
'
' managementEventWatcher1
'
watcher.Query = New System.Management.EventQuery("SELECT * FROM
__InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA
""Win32_PnPEntity""")
AddHandler watcher.EventArrived, AddressOf NewPlugPlay
watcher.Start()
End Sub
Public Sub StopListen()
watcher.Stop()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
StartListen()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
StopListen()
End Sub

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #3
Hi Brad,

Thanks for your quickly reply!

Since I can not reproduce the problem, I suggest you try to modify the
query statement as following.
SELECT * FROM __InstanceCreationEvent WITHIN 30 WHERE TargetInstance ISA
""Win32_PnPEntity"""

You may try to increase the query interval (e.g. change 1 to 30 or larger)
to see if the problem persists.

If you wants to understand WMI, I think the document in SDK is good and
necessary.
Windows Management Instrumentation
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
wmi_start_page.asp
Querying with WQL
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
querying_with_wql.asp
Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #4
Peter,

Thanks for the pointer to the documentation. I'll start experimenting with
the query interval.

Brad

"Peter Huang" <v-******@online.microsoft.com> wrote in message
news:ZG*************@cpmsftngxa07.phx.gbl...
Hi Brad,

Thanks for your quickly reply!

Since I can not reproduce the problem, I suggest you try to modify the
query statement as following.
SELECT * FROM __InstanceCreationEvent WITHIN 30 WHERE TargetInstance ISA
""Win32_PnPEntity"""

You may try to increase the query interval (e.g. change 1 to 30 or larger)
to see if the problem persists.

If you wants to understand WMI, I think the document in SDK is good and
necessary.
Windows Management Instrumentation
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/ wmi_start_page.asp
Querying with WQL
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/ querying_with_wql.asp
Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
2
by: GG | last post by:
Hi, We have a prod server running on SQL server 2000 64 bit. It is a 4cpu server with 16GB of RAM. we have a maxmemory setting of 15.5GB for sql server. Inspite of 15GB being available for sql...
20
by: Philip Carnstam | last post by:
How come .Net applications use so much memory? Every application I compile uses at least 10 MB of memory, even the ones consisting of only a form and nothing else. If I minimize them though the...
4
by: Dan K. | last post by:
Hi NG, first of all i am new to OOP and C# so maybe thats my whole problem :) i wrote a small timer application, like i did if i was starting with programming in vb long time ago. the vb...
1
by: Damien | last post by:
Hi guys, I'm looking for ideas for troubleshooting the following. We've tried some random things to try to treat the symptoms, but none seem robust enough to use when we go live, and we'd rather...
0
by: Dinesh | last post by:
Hi, We are seeing high memory usage (1GB) and subsequently out of memory exception. We are trying to transform the documents using xslt and most importantly using Assembly.Evidence to avoid...
2
by: Mechul | last post by:
Hi people i need serious help here.. I have a forum and my hosting company suspended it cuz of the high usage of sql. We did everything to make lower the usage but its still high. it was ...
1
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
17
by: Cesar | last post by:
Hello people. I'm having a Winform app that contains a webbrowser control that keeps navigating from one page to another permanentrly to make some tests. The problem I'm having is that after a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.