Donate

List Running Computer Processes By Array Names Using LINQ In C# And VB.NET

Here's a snippet on how to retrieve running process in your computer by array names using LINQ.
C# Code
1
2
3
4
5
6
7
8
List<Process> procs = new List<Process>();
procs = new List<string>() { "firefox", "iexplore", "ssms", "notepad++", "chrome" }
            .SelectMany(o => Process.GetProcessesByName(o)).ToList();

foreach (var item in procs)
{
        Console.WriteLine(item.ProcessName);
}

VB.NET
1
2
3
4
5
6
Dim procs As IEnumerable(Of Process) = _
        {"firefox", "iexplore", "ssms", "notepad++", "chrome"}.SelectMany(Function(proc) Process.GetProcessesByName(proc))
For Each p In procs
     Console.WriteLine(p.ProcessName)
Next
Console.ReadLine()
Output
List Running Computer Processes By Array Names  Using LINQ In C# And VB.NET

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.