C# Running Process List

In the context of computer systems, a process refers to a running application or program. The System.Diagnostics namespace in C# provides functions that enable you to manage processes within a system. The Process class, specifically, offers functionality to monitor and control system processes.

using System.Diagnostics;

Process class

The Process class provides functionality to monitor system processes across the network, and to start and stop local system processes. You can retrieve detailed knowledge of process threads and modules both through the Process class itself.

Process[] process = Process.GetProcesses();

Using the Process class, you can perform various operations on processes, including:

  1. Monitoring system processes: The Process class allows you to retrieve information about running processes, such as their IDs, names, resource usage, and more. This information can be used to monitor system activity, track resource consumption, and perform diagnostics.
  2. Starting and stopping local system processes: With the Process class, you can start new local processes by providing the application name or file path, and optionally specifying command-line arguments. Additionally, you can stop local processes programmatically.
  3. Managing process threads and modules: The Process class provides methods to retrieve detailed information about the threads and modules associated with a process. You can obtain information about individual threads running within a process, including their IDs, states, and execution contexts. Similarly, you can access details about the modules (DLLs) loaded into a process, such as their names, memory addresses, and file paths.

The following C# program shows how to retrieve the process name and Memory Allocation of each process from a running system. Drag and drop a Button and ListBox control on your C# Form, and copy and paste the following source code on button click event.

Full Source C#
using System; using System.Windows.Forms; using System.Diagnostics; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Process[] process = Process.GetProcesses(); foreach (Process prs in process) { listBox1.Items.Add(prs.ProcessName + " (" + prs.PrivateMemorySize64.ToString()+ ")"); } } } }


It's important to note that the Process component caches information about process properties to optimize performance. Once the Process component retrieves information about one member of a group (e.g., process threads or modules), it caches the values for the other members within that group. To update the cached values and obtain fresh information, you can call the Refresh method.