Click here to Skip to main content
15,117,830 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

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; 


    while (KeepCalculation)
        NewRawUsageValue = GetCurrentUsageValue();
        CpuUsage = ((int)((NewRawUsageValue - OldRawUsageValue) / 
                                  RefreshInterval)).ToString() + "%";
        OldRawUsageValue = NewRawUsageValue;
Updated 27-Apr-14 10:09am
[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:-

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...

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