Completely Free .NET word API

Resources » Code Snippets » Process

Find Memory usage and CPU usage

Updated: Category: Process
Author: Member Level: GoldPoints: 10

In this article author explain about how to Find Memory usage and CPU usage

This sample code shows to find the RAM (memory) usage and CPU usage of a computer. This method is very usefull in order to monitor the system and particulary the amount of the available RAM in MB (MegaBytes) and the cpu usage in percents.

// Page Level declaration
protected System.Diagnostics.PerformanceCounter cpuCounter;
protected System.Diagnostics.PerformanceCounter ramCounter;

// Put into page load
cpuCounter = new System.Diagnostics.PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
ramCounter = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes");

// Call this method every time you need to know the current cpu usage.
public string getCurrentCpuUsage()
return cpuCounter.NextValue()+"%";

// Call this method every time you need to get the amount of the available RAM in Mb
public string getAvailableRAM()
return ramCounter.NextValue() + "Mb";

// Put this code into button click event
textBox3.Text = getCurrentCpuUsage();
textBox4.Text = getAvailableRAM();

Did you like this resource? Share it with your friends and show your love!

Responses to "Find Memory usage and CPU usage"
Author: rpkumar  08 May 2010   Member Level: Bronze   Points : 1
thanx its really helpful
Richonet Technologies Pvt. Ltd

Guest Author: salam   07 Dec 2011
Thanks, usefull snippet. Can this be used to measure the memory usage by the applications running. What I mean is lets say I develop myapp.exe, while it is running, I display the RAM used by my application in the interface in C#


Post Comment:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India