Processes to XML using LINQ
Posted by codingsense on September 26, 2008
We have seen what is LINQ to objects and LINQ to XML now lets do some work that would need the combination of both.
Let us create an XML file which will consist of top 4 processes that are consuming high memory.
var MyProcess = from Proc in Process.GetProcesses()
where Proc.PagedMemorySize64 > 10000000
orderby Proc.PagedMemorySize64 descending
select new XElement(“Process”,
new XElement(“Name”, Proc.ProcessName),
new XElement(“Memory”, Proc.PagedMemorySize64)
Console.WriteLine(new XElement(“Processes”, MyProcess.Take(4)));
Just have a closer look at what is being done. In MyProcess variable we get the list of all the process in the system those are taking more than 10000000 bytes of memory in desc order. While printing in Console.WriteLine we filter the top 4 process using Take Method.
Keep Learning 🙂