29/09/2014 by Nitesh

How To List the Name of all Running Processes in C#


In this post, we will see how we can print the list of all running processes on a machine using C#. To list all the processes, we will use one of the namespaces provided by Microsoft known as System.Diagnostics. As per MSDN, this namespace provides classes that allow you to interact with system processes, event logs, and performance counters.

This namespace contains a class named Process that we will use to iterate through the process list. So, let’s write some code.

private void ListProcesses()
    Process[] processCollection = Process.GetProcesses();
    foreach (Process p in processCollection)

In the above code snippet, we’re getting the list of all processes using the static GetProcesses() function defined in the Process class. After the list is retrieved, we iterate through each process and prints the process name.

A sample output on my Windows8.1 machine is as below –


Hope you like this post! Keep learning and sharing! Cheers!

#.Net#C##How To?#Process