I am enumerating processes to find if excel.exe
is running (for example).
I get a lot of Win32Exception
from system services and such.
Process[] pps = Process.GetProcesses();
foreach (var process in pps)
{
string module = null;
try
{
module = process.MainModule?.FileName;
}
catch (Win32Exception)
{
continue;
}
which make enumeration to run 500ms instead of 10ms.
Is there a way to figure if a process has main module without triggering the exception? Or any other way to find process exe path?