How to Diagnose System using LINQ Query
This query determines the top 5 memory-using applications currently loaded.
Dim pList = From p In System.Diagnostics.Process.GetProcesses() _ Select ProcessName = p.ProcessName, _ Size = (Format(p.WorkingSet64 / 1000, "#,##0") & " KB"), _ Size64 = p.WorkingSet64 _ Order By Size64 Take 5 Console.WriteLine("These 5 processes are using the most memory:") For Each p In pList Console.WriteLine(p.ProcessName & " - " & p.Size) Next
Result:
These 5 processes are using the most memory:
Idle - 16 KB
System - 217 KB
smss - 381 KB
lsass - 934 KB
vpcmap - 958 KB
james.curranPosted Dec 20, 2010, 12:53 PM
Those are actually the 5 using the LEAST memory. You saying for them to be sorted ascendingly (lowest first) I'm not sure of the VB, but the corrrect C# is: (from p in System.Diagnostics.Process.GetProcesses() let Size64 = p.WorkingSet64 orderby Size64 descending select new { p.ProcessName, Size = String.Format("{0:#,##0} KB", p.WorkingSet64/1000) }).Take(5)