79783727

Date: 2025-10-06 13:17:10
Score: 0.5
Natty:
Report link
class Program
{
    static void Main()
    {
        string processName = "notepad"; 

        try
        {            
            var counter = new PerformanceCounter("Process", "Working Set - Private", processName);
            float memoryBytes = counter.NextValue();

            double memoryMB = memoryBytes / 1024 / 1024;
            
            Console.WriteLine($"[{processName}] Memory (Task Manager 'Memory' column): {memoryMB:F1} MB");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
        }
        Console.WriteLine();
        Console.WriteLine("Press any key to exit...");
        Console.ReadKey(); 
    }
}

The memory value obtained using this code matches the value displayed in Task Manager’s Memory column, as shown in the screenshot below

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Alparslan ŞEN