using System; using Diagnostics = System.Diagnostics; using Win32Exception = System.ComponentModel.Win32Exception; using Path = System.IO.Path; namespace ProcessInfo { public class Process { private String name; private int pid; private long workingSet; private Process() { } public Process( Diagnostics.Process process ) { if ( process == null ) { throw new ArgumentNullException( "process" ); } this.pid = process.Id; this.workingSet = process.WorkingSet64; if ( process.Id == 0 ) { // the process name is "Idle"; special case so it appears the same as task manager name = "System Idle Process"; } else { try { name = process.MainModule.ModuleName; } catch ( Win32Exception ) { // some system processes don't have a main module; instead use the process name name = process.ProcessName; } } } public override String ToString() { return name; } public int Pid { get { return pid; } } public String Name { get { return name; } } public String NameWithoutExtension { get { return Path.GetFileNameWithoutExtension( Name ); } } public long WorkingSet { get { return workingSet; } } } }