We may come across different scenarios where we need to get the list of all applications/processes running in the background of the Window OS.
Manually we can go to the task manager and check the processes tab to see the list.
But if we are trying to automate a scenario and if we want to do any action like Kill the process, close the process, Get the runtime of the process, Know used memory, etc we may need to take the list of running processes programatically.
For that, we can use the Processes method under System.Diagnostics Class
A sample code to get all running proccesses and print the name to the console is given below.
We can customize this to any format according to our requirements.
public void getAllRunningProcesses() { Process[] processlist = Process.GetProcesses(); foreach (Process theprocess in processlist) { Console.WriteLine(theprocess.ProcessName); } }
No comments:
Post a Comment