OS Processes monitoring

For a personal app I've needed to pool the OS for running processes, and with .NET couldn't be easier...

Add a reference and to using statements...

using System.ServiceProcess;
using System.Diagnostics;

And with just one line of code it's done

Process[] runningProcesses = Process.GetProcesses(System.Environment.MachineName);

The Process class gives some info, like process ID, startup time, memory in use... Beware that some process may throw some Win32Exceptions when trying to access data (it happened to me with the Idle process when trying to get startup time).

Oh, and with that class you can launch (and monitor) new process too, even attaching events to them (like a wonderful OnExited() event handler).

Comments?

Posted by Kartones on 2006-04-18