C # Process.Modules is very slow

My code is retrieving all loaded module names from each running process, my approach is similar to this answer .

Here is my code:

Process[] procs = Process.GetProcesses();            
foreach (Process p in procs)
{                  
    foreach (ProcessModule item in p.Modules)
    {
        Console.WriteLine(item.FileName);
    }
}

      

For some reason this approach has very poor performance :(

Is there any other method or approach to get the names of all these modules?

Any other solution that will run faster than this would be great

TIA

+3


source to share


1 answer


You can try adding some parallelization to speed things up:



 Parallel.ForEach(Process.GetProcesses(),
            process =>
            {
                foreach (ProcessModule m in process.Modules)
                {
                    Console.WriteLine(m.FileName);
                }
            });

      

+3


source







All Articles