This documentation is archived and is not being maintained.

Managing Processes Sample 

Download sample

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

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To open the sample file in Solution Explorer

  1. Click Download Sample.

    The File Download message box appears.

  2. Click Open, and on the left column of the zip folder window, click Extract all files.

    The Extraction Wizard opens.

  3. Click Next. You can change the directory that the files will be extracted to, and then click Next again.

  4. Make sure that the Show extracted files check box is selected, and click Finish.

  5. Double-click the sample's .sln file.

    The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.

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.


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