Simple example...
bool processIsRunning(string process)
{
return (System.Diagnostics.Process.GetProcessesByName(process).Length != 0);
}
Oops... forgot the mem usage, etc...
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);
}
(I'll leave the mechanics of getting the data out of the method to you - it's 17:15 here, and I'm ready to go home. :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…