I want to programmatically obtain a list of running (desktop) applications, and then I want to display this list to the user. It should be something similar to the application list displayed in the Windows Task Manager.
How can I create this in C#? Specifically, I need a way to obtain that list of currently running applications.
Open the terminal window on Ubuntu Linux. For remote Ubuntu Linux server use the ssh command for log in purpose. Type the ps aux command to see all running process in Ubuntu Linux. Alternatively, you can issue the top command/htop command to view running process in Ubuntu Linux.
You can start Task Manager by pressing the key combination Ctrl + Shift + Esc. You can also reach it by right-clicking on the task bar and choosing Task Manager. Under Processes>Apps you see the software that is currently open. This overview should be straight forward these are all the programs you are currently using.
To see what apps run on your machine, search "background apps" and select the first option you see. You will go to System Settings > Background Apps and can see what apps are running in the background on your machine. Here you may also turn off and on these apps.
You can use the Process.GetProcesses
method to provide information about all of the processes that are currently running on your computer.
However, this shows all running processes, including ones that are not necessarily shown on the taskbar. So what you'll need to do is filter out those processes that have an empty MainWindowTitle
.The above-linked documentation explains why this works:
A process has a main window associated with it only if the process has a graphical interface. If the associated process does not have a main window (so that MainWindowHandle is zero), MainWindowTitle is an empty string ("").
So, you could use something like the following code, which will print out (to a console window) a list of all currently running applications that are visible on your taskbar:
Process[] processes = Process.GetProcesses();
foreach (var proc in processes)
{
if (!string.IsNullOrEmpty(proc.MainWindowTitle))
Console.WriteLine(proc.MainWindowTitle);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With