How to get list of all processes running in C#?
To get list of all process running in C#, we can use methodProcess.GetProcesses()
to return the list of all processes objects, and then loop through these processes and get ProcessName
and Id
properties.Remember to include
using System.Diagnostics;
.Example
using System;
using System.Diagnostics;
public class Example
{
public static void Main()
{
Process[] processlist = Process.GetProcesses();
foreach (Process theprocess in processlist)
{
Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id);
}
}
}