Process
A process is an operating system concept and it is the smallest unit of isolation provided by Windows OS. Each application or piece of code runs in Windows runs under the boundary of a process. Application isolation makes sure the failure of one process does not affect the functioning of another process. It is also necessary to ensure that code running in one application cannot adversely affect other, applications.
When you run an application, Windows creates a process for the application with a specific process id and other attributes. Each process is allocated with necessary memory and a set of resources.
Every Windows process contains at least one thread which takes care of the application execution. Processes can have many threads and they speed up execution and give more responsiveness but a process that contains a single primary thread of execution is considered to be more thread-safe.
In Figure 1, you can see how the processes running in the machine are listed. Each process has name, id, description, etc. and each process can be uniquely identified using process ID.
System.Diagnostics provides a number of classes to deal with processes including Process class.
Figure 1

Let us try an application using C# to demonstrate working with the process. The code in Listing 1 explains two things,
How to start a process, how to kill/terminate a process.
- using System;
- using System.Diagnostics;
- namespace SampleProcess
- {
- public class SomeProcess
- {
- public static void Main(string[] args)
- {
- Process myProcess = new Process();
- try
- {
- // myProcess.StartInfo.UseShellExecute = false;
- // You can start any process, HelloWorld is a do-nothing example.
- myProcess.StartInfo.FileName = @"C:\Users\[UserID]\source\repos\BMIRuleEngine\BMIRuleEngine.exe";
- // myProcess.StartInfo.CreateNoWindow = true;
- myProcess.Start();
- // The process you are starting should terminate itself.
- // If you set CreateNoWindow = true, the application will run without a window and
- // it must terminate itself or you can do it programmatically from this application using the Kill method.
- // Do your other tasks here
- // Let us kill the process which we created because my application doesn’t terminate by itself.
- Process[] processes = Process.GetProcessesByName("BMIRuleEngine");
- foreach(Process process in processes)
- {
- process.Kill();
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- }
Listing 1
- StartInfo - gets or sets the properties to pass to the Process.Start() of the Process.
- StartInfo.CreateNoWindow - help you specify whether you need to run the application with a window or without a window.
- StartInfo.UseShellExecute - help you specify whether to use the operating system shell to start the process or not. If you set UseShellExecute=True, the application will use the operating system shell to start processes. With OS shell, you can start any document (which is any registered file type associated with an executable that has a default open action) and perform operations on the file, such as printing, by using the Process object. If you set UseShellExecute to false, you can start only executables by using the Process object.
- Arguments – help you specify arguments to be passed to the application.
There are many other useful properties available for the Process class, please check it out.
Application Domain
Application Domain or AppDomain is one of the most powerful features of the .NET framework. AppDomain can be considered as a light-weight process. An application domain is a .NET concept whereas the process is an operating system concept. Both have many characteristics in common. A process can contain multiple app domains and each one provides a unit of isolation within that process. Most importantly, only those applications are written in .net, or in other words, only managed applications will have application domain.
Application domain provides isolation between code running in different app domains. App Domain is a logical container for code and data just like process and has separate memory space and access to resources. App domain also serves as a boundary like a process that does avoid any accidental or illegal attempts to access the data of an object in one running application from another.
System.AppDomain class provides you ways to deal with the application domain. It provides methods to create a new application domain, unload domain from memory, etc.
Why we need App Domain while we have Process
This is the first question that came to my mind while I first heard about application domains.
A Process is much heavier and expensive to create and maintain. So, the server would have a tough time managing the processes. So, when Microsoft developed the .Net framework, they introduced the concept of Application Domain and it is an integral part of the .net framework.
While AppDomains still offer many of the features that a Windows process offers, they are more efficient than a process by enabling multiple assemblies to be run in separate application domains without the overhead of launching separate processes. An App Domain is relatively cheaper when compared to the process to create, and has relatively less overhead to maintain.
Think about a server that hosts hundreds of applications. Before the app domain was introduced, each running application used to create one process. AppDomain is of great advantage for ISP (Internet Service Provider) who hosts hundreds of applications. Because each application can be contained in an application domain and a process can contain many such AppDomains, thus providing a lot of cost-saving.
In short, any process running a managed application will have at least one app domain in it. Since AppDomain is a .NET concept, any process running unmanaged code will not have any application domain.
Figure 2 will help you understand the concept better.
Figure 2

Process A runs managed code with one application domain while Process B runs managed code has three application domains. Note that Process C which runs unmanaged code has no application domain.
Code and data are safely isolated using the boundary provided by the AppDomain. If two AppDomains want to communicate with each other pass objects, .NET techniques such as Remoting or Web Services should be used.
Application Domain Example
Create a Console Application
I am using Visual Studio 2017 for this demo.
File -> New -> Project
From the left pane, Visual C# -> Windows classic desktop
On the right pane, choose Console App.
Alternatively, you can type the console app in the search box which is located at the top right corner of the window, and choose the type of solution you want to create.
There will be a Console App (.NET Framework) and Console App (.NET Core).
If you are going to use the application only in windows, choose .NET framework one.
.NET Core project will help you create a command-line application that can work on .NET Core on Windows, Linux, and macOS.
For our purpose, the .NET framework is enough.
There is a Visual C# version and a Visual Basic version for the above two types of application, choose the right one based on which language you are going to use.
I am going to use C# one instead of the VB one.
Name the project as AppDomainSample and click OK.
Figure 3

Add the below code shown in Listing 2 to the Program class and build the application.





Joandre TaitPosted Mar 29, 2023, 10:46 PM
Think your tutorial here is being sold by a 3rd party. Seems that their screenshots match yours exactly and the blurred out pages in the "preview" can clearly be made out as screenshots from this C# Corner content: https://www.studocu.com/row/document/government-college-university-faisalabad/web-design-and-development/application-domain/35343312
RomainPosted Oct 20, 2020, 2:41 AM
Firstly thank you for this article.Also, I have a question. I am working on a application which works with C# , C++/ClI and C++ code.The entry point is C# dll and after we move to C++/CLI wrapper in order to launch a C++ executable. The C++ executable is launched in a new thread and in this new thread context, some assembly files are not loaded. My question is how to load them ? Or many there is a technical way to load assembly for different threads.
Tridip BhattacharjeePosted Jan 8, 2018, 4:15 AM
How two routine running in 2 different app domain in same process can communicate with each other?