Processes

I'll let the code speak for itself:

using Console   = System.Console;
using Debug   = System.Diagnostics.Debug;
using Process   = System.Diagnostics.Process;

namespace Processes { public class Program { public static void Main(string[] args) { Console.WriteLine(" -> Processes and .NET");

#region [ Current Process ]

Process current = Process.GetCurrentProcess();

Debug.Assert(current != null, "The current process can't be null."); Debug.Assert(current.HasExited == false, "The current process should be active.");

Console.WriteLine(" -> Information about the current process: "); Console.WriteLine(" -> Id: " + current.Id); Console.WriteLine(" -> Name: " + current.ProcessName); Console.WriteLine(" -> Title: " + current.MainWindowTitle);

Console.ReadLine();

#endregion

#region [ Active Processes ]

Console.WriteLine(" -> A list of all active processes: ");

Process[] activeProcesses = Process.GetProcesses();

foreach (Process process in activeProcesses) { Debug.Assert(process != null, "Process shouldn't be null.");

Console.WriteLine(<span class="str">" -&gt; Name: "</span> + process.ProcessName);

}

Console.ReadLine();

#endregion

#region [ Start Notepad ]

System.Console.WriteLine(" -> Starting Notepad...");

Process notepad = Process.Start("notepad.exe");

Debug.Assert(notepad != null, "Notepad shouldn't be null.");

Console.ReadLine();

#endregion

#region [ Kill Notepad ]

Console.WriteLine(" -> Killing notepad...");

Debug.Assert(notepad != null, "Notepad shouldn't be null.");

notepad.Kill(); notepad = null;

Console.ReadLine();

#endregion

Console.WriteLine(" -> All done!");

Console.ReadLine(); } } }