How to ignore win32 exception? module process

后端 未结 1 706
失恋的感觉
失恋的感觉 2021-01-26 05:51

i tried to create to look dll that loaded in process. but i got error when getting process with system.dll. it throw error message:

System.ComponentModel.

相关标签:
1条回答
  • 2021-01-26 06:07

    This will ignore Exceptions thrown by accessing process.Modules.

    public IEnumerable<string> GetProcessFileName(string searchBy)
    {
        foreach(var process in Process.GetProcesses())
        {
            try{
                var p = process.Modules.Cast<ProcessModule>()
                    .Where(m => m.FileName.Contains(searchBy))
                    .Select(x => x.FileName);           
                return p;
            }
            catch(Exception e){
                //write to log
                //Console.Write(e);     
            }
        }
    
        return Enumerable.Empty<string>();
    }
    
    0 讨论(0)
提交回复
热议问题