dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Membersbaskar
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Code Snippets » Process

Find Memory usage and CPU usage


Posted Date:     Category: Process    
Author: Member Level: Gold    Points: 10



 


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 2010Member Level: Bronze   Points : 1
thanx its really helpful
Programmer
Richonet Technologies Pvt. Ltd
http://www.richonet.com



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#


Feedbacks      

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.


    Next Resource: Start a process and wait until it exits
    Previous Resource: How to monitor the network performance using Performance counter?
    Return to Resources
    Post New Resource
    Category: Process


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.