Share via


Managing Processes Sample

This sample uses objects in the System.Diagnostics namespace to gather information about a running process.

To get samples and instructions for installing them

  • Do one or more of the following:

    • On the Help menu, click Samples.

      The Readme displays information about samples.

    • Visit the Visual Studio 2008 Samples Web site. The most recent versions of samples are available there.

    • Locate samples on the computer on which Visual Studio is installed. By default, samples and a Readme file are installed in drive:\Program Files\Microsoft Visual Studio 9.0\Samples\lcid. For Express editions of Visual Studio, all samples are located online.

For more information, see Visual Studio Samples.

Security noteSecurity Note:

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

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.

See Also

Reference

Process

System.Diagnostics

ProcessThread

Threads