Hi all,
Trying to programmatically get the private working set of a process.
Currently I am able to get the working set without issue but having trouble getting the private working set.
Here's method:
private void GetProcessesForServer(string serverName)
{
var runningProcesses = new Process[0];
try
{
runningProcesses = Process.GetProcesses(serverName);
}
catch (Exception e)
{
ResultsPanel.Controls.Add(new Label { Text = string.Format("There was an error: {0}", e.GetBaseException().Message) });
}
IOrderedEnumerable<CustomProcess> processes = runningProcesses
.Select(process => new CustomProcess(process.Id, process.ProcessName, (process.WorkingSet64 / 1024)))
.ToList()
.OrderBy(process => process.ProcessName);
if (processes.Count() > 0)
ResultsLabel.Text = string.Format("Current running processes on {0}", ServerNamesDropDown.SelectedItem.Text);
ResultsGridView.DataSource = processes;
ResultsGridView.DataBind();
}
So I'm passing in a server name then trying to get all the running processes for that server then binding the list of processes to a grid view. Everything works without any issues however I need to get the private working set - similar to what you see in Windows Task manager - rather than the total working set.
Many thanks, Tim