I'm having a little trouble monitoring memory usage of an application. I already have some code that gets the process by name.. But there can be multiple processes with the same name. So it will only monitor the first process in the list.. So I'm trying to get it by PID. But I have no code that works.. But here is what I used when I got it by name:
private void SetMemory()
{
PerformanceCounter performanceCounter = new PerformanceCounter
{
CategoryName = "Process",
CounterName = "Working Set",
InstanceName = MinecraftProcess.Process.ProcessName
};
try
{
string text = ((uint)performanceCounter.NextValue() / 1024 / 1000).ToString("N0") + " MB";
MemoryValue.Text = text;
radProgressBar1.Value1 = ((int)performanceCounter.NextValue() / 1024 / 1000);
}
catch (Exception ex)
{
}
}
EDIT: I have the PID. But I don't know how to start the monitoring from that.