Tuesday, October 9, 2007

LINQ to Processes


var procs = ( from proc in Process.GetProcesses()
where proc.PriorityClass == ProcessPriorityClass.Normal &&
proc.StartTime < DateTime.Now.AddHours( -6 ) &&
proc.TotalProcessorTime.TotalMinutes > 30 &&
proc.Responding &&
!proc.MainModule.FileVersionInfo.IsDebug
select proc ).ToList();

This query pulls back a List of Process objects that are running with normal priority, have been running for more than 6 hours, have used more than 30 minutes of processor time, are still responding and are not debug builds.

If security settings prevent you from getting details on a process, this query will throw an exception.

No comments: