Display the process statistics until the user closes the program : Process « Development « C# / CSharp Tutorial






using System;
using System.Diagnostics;

    class ProcessMonitorSample
    {
        public static void Main()
        {
            Process myProcess = null;
            myProcess = Process.Start("NotePad.exe");
            do
            {
                if (!myProcess.HasExited)
                {
                    myProcess.Refresh();
                    Console.WriteLine("{0} -", myProcess.ToString());
                    Console.WriteLine("physical memory usage: {0}",myProcess.WorkingSet64);
                    Console.WriteLine("base priority: {0}",myProcess.BasePriority);
                    Console.WriteLine("priority class: {0}",myProcess.PriorityClass);
                    Console.WriteLine("user processor time: {0}",myProcess.UserProcessorTime);
                    Console.WriteLine("privileged processor time: {0}",myProcess.PrivilegedProcessorTime);
                    Console.WriteLine("total processor time: {0}",myProcess.TotalProcessorTime);
                    Console.WriteLine("PagedSystemMemorySize64: {0}",myProcess.PagedSystemMemorySize64);
                    Console.WriteLine("PagedMemorySize64: {0}",myProcess.PagedMemorySize64);

                    Console.WriteLine(myProcess.PeakPagedMemorySize64);
                    Console.WriteLine(myProcess.PeakVirtualMemorySize64);
                    Console.WriteLine(myProcess.PeakWorkingSet64);

                    if (myProcess.Responding)
                    {
                        Console.WriteLine("Status = Running");
                    }
                    else
                    {
                        Console.WriteLine("Status = Not Responding");
                    }
                }
            }
            while (!myProcess.WaitForExit(1000));
            Console.WriteLine("Process exit code: {0}",myProcess.ExitCode);
        }
    }








14.15.Process
14.15.1.Starting Processes by using ProcessStartInfo
14.15.2.Starting a new process.
14.15.3.Detecting Process Completion
14.15.4.Redirecting Process Output
14.15.5.Get all processes on local machine
14.15.6.Enumerate over threads in a given PID
14.15.7.Enumerate over mods in a given PID
14.15.8.Launch / kill a process
14.15.9.Threads in Current Process
14.15.10.Property of current Process
14.15.11.Change priority for current process
14.15.12.List all process threads in current running processes
14.15.13.All current running processes
14.15.14.Listing processes on a remote machine
14.15.15.Get processes by name
14.15.16.Get all processes running on the local computer
14.15.17.Get all processes running on the remote computer
14.15.18.Get a process on the local computer, using the process id
14.15.19.Get a process on a remote computer, using the process id
14.15.20.Display the process statistics until the user closes the program
14.15.21.Uses the ProcessStartInfo class to start new processes, both in a minimized mode
14.15.22.Using an IP address to specify the machineName parameter
14.15.23.Start a Web page using a browser associated with .html and .asp files
14.15.24.Using the computer alias (do not precede with "\\")