Reputation: 4677
I'm trying to use a Memory Performance Counter:
System.Diagnostics.PerformanceCounter theMemCounter =
new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes",
System.Diagnostics.Process.GetCurrentProcess().ProcessName, true);
var memStart = theMemCounter.NextValue();
But in the second line i'm getting the following error:
Counter is single instance, instance name 'WebDev.WebServer40' is not valid for this counter category.
What is the problem?
Upvotes: 1
Views: 1948
Reputation: 154
Ottoni, I don't think you can specify a process to this particular Performance Counter, since it monitors the available memory on the whole system.
Maybe the perfcounter you're looking for is ".NET CLR Memory(INSTANCE)# Bytes in all Heaps" or some other in the .NET CLR Memory category, which is able to monitor memory usage for all or a specified .net application.
More info on this category here: http://msdn.microsoft.com/en-us/library/x2tyfybc.aspx
--EDIT
Solution:
System.Diagnostics.PerformanceCounter theMemCounter =
new System.Diagnostics.PerformanceCounter("Process", "Working Set",
System.Diagnostics.Process.GetCurrentProcess().ProcessName);
var memStart = theMemCounter.NextValue() / 1024 / 1024;
Upvotes: 2