From: Andrus on
I need to return CPU and memory columns for each process in server from web
service like task manager shows by default.
I tried code below but s.TotalProcessorTime throws Win32exception with stack
below.
How to get CPU and real memory size from server using web service ?

Andrus.

static void Processes(StringBuilder sb)
{
List<Process> processes = new List<Process>();
foreach (Process process in Process.GetProcesses())
processes.Add(process);

processes.Sort((a, b) =>
{
return Math.Sign(b.PrivateMemorySize64 -
a.PrivateMemorySize64);
});

foreach (var s in processes)
{
sb.AppendLine(s.ProcessName + " CPU " +
s.TotalProcessorTime.ToString() + " " +
" Memory " + s.PrivateMemorySize64/1024+
" kb");
}
}



System.ComponentModel.Win32Exception:
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32
access, Boolean throwIfExited)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean
throwIfExited)
at System.Diagnostics.Process.GetProcessTimes()
at System.Diagnostics.Process.get_TotalProcessorTime()
....