More Performance Counters

    Date: 08/14/06 (C Sharp)    Keywords: no keywords

    Could anyone please help me with .NET performance counters? I am trying to read the % Processor Time of all of the currently running processes on the system. Here is my code. Assume that thisInstances is a string array containing elements, each of which is one process running on the system (I checked this myself using the debugger):

    					foreach (string thisInstance in thisInstances)
    					{
    						thisPerfCounter = new PerformanceCounter();
    						thisPerfCounter.CategoryName = "Process";
    						thisPerfCounter.CounterName = "% Processor Time";
    						thisPerfCounter.InstanceName = thisInstance;
    						thisPerfCounter.NextValue();
    
    							System.Windows.Forms.MessageBox.Show(thisInstance + ": " + thisPerfCounter.NextValue().ToString());
    						thisPerfCounter.Dispose();
    						thisPerfCounter = null;
    						thisProcess = null;
    					}
    


    I see a messagebox for every process on the system, but each and every one has a value of 0. What gives? I've read articles, copied code from console applications that actually work, etc. I'm not sure what I'm doing wrong.

    Any suggestions?

    Source: http://community.livejournal.com/csharp/72874.html

« I hope this isn't... || ADO.Net vNext »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home