如何检测进程是否已在Windows任务管理器下运行?我也想获得内存和CPU使用率.
简单的例子......
bool processIsRunning(string process) { return (System.Diagnostics.Process.GetProcessesByName(process).Length != 0); }
糟糕...忘记了内存使用等...
bool processIsRunning(string process) { System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName(process); foreach (System.Diagnostics.Process proc in processes) { Console.WriteLine("Current physical memory : " + proc.WorkingSet64.ToString()); Console.WriteLine("Total processor time : " + proc.TotalProcessorTime.ToString()); Console.WriteLine("Virtual memory size : " + proc.VirtualMemorySize64.ToString()); } return (processes.Length != 0); }
(我将留下从方法中获取数据的机制 - 这是17:15,我准备回家了.:)
您是否查看了System.Diagnostics.Process类.