Managing Processes Sample

To get samples and instructions for installing them, see the following:

  • Click Samples on the Visual Studio Help menu.

    For more information, see Locating Sample Files.

  • The most recent versions and the complete list of samples are available on the Visual Studio 2008 Samples Web site.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied to a folder under \Program Files\Visual Studio 9\Samples\. For Visual Studio Express Editions, all samples are located on the Internet.

To run this sample

  1. Press F5.

  2. Click a process to have its details and thread data loaded. Use the menus to view the list of modules loaded by a particular process. Press F5 while the program is running to refresh the list of processes.

Demonstrates

The processes on the current computer are displayed in a ListView control by calling the GetProcesses method. When a process is selected, details about that process are shown in another ListView control. The process details are retrieved using the Process instance representing the process. The Threads property is used to enumerate the threads of the process, which are then displayed in another ListView control. Each thread is represented by a ProcessThread instance. The modules for each process can be inspected by selecting a process and then clicking Modules in the main menu or the context menu. A separate form displays the modules loaded by the process and includes the name of the file where the code was loaded.

There are three processes that do not supply complete information:

  • _Total   This process is added in code and does not represent a process. It is used to provide summary execution time, and processor utilization.

  • Idle   Though returned as a process, it is not a process that can return data.

  • System   This process does not expose module information.

You may not have access to all the information about a process. In that case, a message box is displayed.