c# - How to check if process is still running before calling Process.GetProcessById? -
c# - How to check if process is still running before calling Process.GetProcessById? -
in .net process.getprocessbyid throws exception if process id not running. how safely phone call method won't throw exception? thinking like
if(process.isrunning(id)) homecoming process.getprocessbyid(id); else homecoming null; //or else but can't find method check id, other getting running processes , check whether id exist in list.
public process getprocbyid(int id) { process[] processlist = process.getprocesses(); homecoming processlist.firstordefault(pr => pr.id == id); }
i looked within process.getprocessbyid method.
it uses internal static class processmanager ensure, process runs. processmanager gets processes running in scheme , checks there ids, think best way it.
so should consider overhead of exception or overhead of process array.
c# .net system.diagnostics
Comments
Post a Comment