C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Find Memory usage and CPU usage


Posted Date: 05 Mar 2007    Resource Type: Code Snippets    Category: Process

Posted By: Md Zafar Imam       Member Level: Gold
Rating:     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();




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Start a process and wait until it exits
Previous Resource: How to monitor the network performance using Performance counter?
Return to Discussion Resource Index
Post New Resource
Category: Process


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

SPOC

Contact Us    Privacy Policy    Terms Of Use