Click here to Skip to main content
15,029,039 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI Friends,
i am using function below mention is which i have calculate overall CPU usage

but i want function in i will pass process name as parameter and get cpu usage, Ram usage and tread.

please help for this task

VB
private void CalcCpu()
{
    // refresh delay 1.5 seconds    
    int RefreshInterval = 1500; 
    // keeps the previous usage value.
    long OldRawUsageValue = GetCurrentUsageValue(); 
    // keeps the current usage value.
    long NewRawUsageValue;
    // holds the cpu usage in a friendly reading way. 
    string CpuUsage; 

    Thread.Sleep(RefreshInterval);

    while (KeepCalculation)
    {
        NewRawUsageValue = GetCurrentUsageValue();
        CpuUsage = ((int)((NewRawUsageValue - OldRawUsageValue) / 
                                  RefreshInterval)).ToString() + "%";
        Thread.Sleep(RefreshInterval);
        OldRawUsageValue = NewRawUsageValue;
    }
}
Posted
Updated 27-Apr-14 9:09am
v2
Comments
[no name] 27-Apr-14 15:00pm
   
So what sort of help are you looking for? Sounds more like you want someone to write this code for you.

Dear It simple function in which as parameter pass process name get return CPU Usage for that particular process
   
There is code in this article[^] for reading performance counters.

The specific code it uses is:-

VB
Imports System.Diagnostics

If PerformanceCounterCategory.InstanceExists( applicationInstanceName , "% Processor Time") Then
  ' Code to use that performance counter....

End If


I would recommend you do NOT use Thread.Sleep though...
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900