. Net (C #): monitor CPU and memory usage

Source: Internet
Author: User
Tags visual studio 2010

Update:

For the complete task manager, see:

Mgen lightweight Task Manager Update and introduction

 

Recently, I used C #/WPF to write a Task Manager program. I first put the CPU and memory monitoring part separately.

 

Displays the same data as the task manager:

 

Download the current version of the program and source code

Note: This is an archive of Microsoft SkyDrive. Please download it directly in your browser. Some download tools may not be available for download.

Running Environment:. NET Framework 4.0 client profile

Source code environment: Visual Studio 2010

 

For more information about the code and CPU, see:

. Net (C #) Monitoring CPU usage

. Net (C #) to obtain the CPU usage of the process

 

Memory is interesting and there are many methods. You can use win32_physicalmemory of WMI. However, because the program needs to refresh information frequently (once per second), it will be slow to Use WMI. The second is to use the globalmemorystatus method of the API. The disadvantage is that some column routines (dllimport, parameter messages…) need to be called by the platform ......). The program uses the third method to directly reference Microsoft. visualBasic. DLL class library (in. the Class Library added after Net Framework 2.0, which belongs. net Framework itself), and use the availablephysicalmemory and totalphysicalmemory of the computerinfo type to obtain the current remaining/all physical memory. Note that each time you obtain the preceding attributes, their values are automatically refreshed without calling other methods.

 

In fact, the third method also calls the globalmemorystatus API method internally. You can find the corresponding clues in ilspy. (The computerinfo private refresh method calls the nativemethods. globalmemorystatus platform call ).

 

For more information about memory, see:

. Net (C #): gets the private working set of the process's memory

. Net (C #) makes a system information viewer.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.