In order to get a list of running processes in C#, you can use the Process class. This class provides a list of processes that are currently running. You can also use the Process.Start and Process.Stop methods to stop or start a process. The following code example shows how to get a list of running processes in C#: using System; using System.IO; using System.Threading; namespace RunningProcesses { public class Program { static void Main(string[] args) { // Get the process name string processName = “C:\Users\username\AppData\Roaming.Microsoft.NETFramework.NETworking\v3.5\WPF” ; // Get the process ID string processID = “7b8cde1-e4bf-11e2-bfe8-0025906a929f” ; // Get the thread count int threadCount = 0 ; while (!processName.EndsWith("")) { Console.WriteLine(processName); ThreadPoolExecutor executor = new ThreadPoolExecutor(); executor.Start(processID); threadCount++; } } } }
The System.Diagnostics.Process object gives you access to functionality enabling you to manage system processes. We will use this object to get a list of running processes.
Add this line to your using list:
Now you can get a list of the processes with the Process.GetProcesses() method, as seen in this example:
Some interesting properties of the Process object:
foreach(Process theprocess in processlist){ Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id); }
The .NET framework really makes things simple!