Processes

Added in .NET 1.1
A process is a small program that can run on a computer.
It can own resources (memory, device handlers, sockets etc)
A process is usually an executable file that does not share resources.
An application is loaded into its own process.


System.Diagnostics.Process

You can start a process by calling the Start method and passing in the name of the executable file as an argument.

System.Diagnostics.Process notepad_process; 
System.Diagnostics.Process excel_process;

notepad_process = System.Diagnostics.Process.Start("notepad.exe");
excel_process = System.Diagnostics.Process.Start("excel.exe");

System.Threading.Thread.Sleep(10000); //wait for 10 seconds

notepad_process.CloseMainWindow();
excel_process.CloseMainWindow();


Process Priority

Every process has a read-only BasePriority property that indicates its priority.
Realtime (24) - runs without interruption
High (13) - other processes can run occasionally
Normal (8) - allocates equally among all the other priorities
Idle (4) -


It is possible to change this priority by assigning a different value to the PriorityClass property

excel_process.PriorityClass = System.Diagnostics.ProcessPriorityClass.High 

List All


foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses() ) 
{
   System.Console.WriteLine(p.ProcessName);
   System.Console.WriteLine(p.BasePriority);
   System.Console.WriteLine(p.Threads.Count);
   System.Console.WriteLine(p.WorkingSet64/1024.0); //physical memory usage
}

System.Diagnostics.ProcessStartInfo

It is possible to redirect input/output using the ProcessStartInfo class.
You can use this class for better control over the process that is started.
In this example we are running a command prompt and getting a list of all the directories and then sending this information to a text file.


Create a New Project
Find Console App
untick "Use Top Level Statements"


System.Diagnostics.ProcessStartInfo start_info; 
start_info = ProcessStartInfo();
start_info.FileName = "cmd.exe";
start_info.Arguments = @"/C dir *";
start_info.CreateNoWindow = true;
start_info.RedirectStandardOutput = true;
start_info.UseShellExecute = false;

System.Diagnostics.Process? process_files;
process_files = Process.Start(start_info);

if (process_files != null)
{
   System.IO.StreamReader reader = process_files.StandardOutput;
   string results = reader.ReadToEnd();
   System.Console.WriteLine(results);
}


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext