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.