Witam.
W mojej aplikacji uruchamiam jakiś proces (w przykładzie notatnik):
Process process = Process.Start("notepad.exe");
Chciałbym móc wyświetlać bieżące zużycie zasobów tego procesu, czyli wartości takie jak w menedżerze zadań.
Próbowałem różnych wariacji takiego kodu:
public partial class Form1 : Form
{
Process process;
PerformanceCounter performanceCounter;
int memsize = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
process = Process.Start("notepad.exe");
performanceCounter = new PerformanceCounter();
performanceCounter.CategoryName = "Process";
performanceCounter.CounterName = "Working Set - Private";
performanceCounter.InstanceName = process.ProcessName;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
memsize = Convert.ToInt32(performanceCounter.NextValue()) / (int)(1024);
label1.Text = "" + memsize + Environment.NewLine;
label1.Text += "" + performanceCounter.RawValue + Environment.NewLine;
label1.Text += "" + performanceCounter.NextSample().RawValue + Environment.NewLine;
label1.Text += "" + process.VirtualMemorySize64;
label1.Text += "" + process.PagedMemorySize64 + Environment.NewLine;
label1.Text += "" + process.PrivateMemorySize64 + Environment.NewLine;
label1.Text += "" + process.PeakVirtualMemorySize64 + Environment.NewLine;
label1.Text += "" + process.PagedSystemMemorySize64 + Environment.NewLine;
label1.Text += "" + process.PeakPagedMemorySize64 + Environment.NewLine;
label1.Text += "" + process.NonpagedSystemMemorySize64 + Environment.NewLine;
}
}
Na labelu pojawiają się jakieś wartości, ale przy wklejaniu/pisaniu w notatniku te wartości się nie zmieniają (w menedżerze zadań tak).
Jakieś pomysły jak pobierać te wartości?