ASP.NET introduces the concept of an Application Domain which is known as AppDomain for short. It can be considered as a lightweight process which is both a container and boundary. The .NET runtime uses an AppDomain as a container for code and data, just like the operating system uses a process as a container for code and data. As the operating system uses a process to isolate misbehaving code, the .NET runtime uses an AppDomain to isolate code inside a secure boundary.
The CLR can allow the multiple .NET applications to run in a single AppDomain. Mulitple Appdomains can exist in Win32 process.
How to create AppDomain
AppDomains are created using the CreateDomain method. AppDomain instances are used to load and execute assemblies (Assembly). When an AppDomain is no longer in use, it can be unloaded.
- public class MyAppDomain: MarshalByRefObject
- {
- public string GetInfo()
- {
- return AppDomain.CurrentDomain.FriendlyName;
- }
- }
- public class MyApp
- {
- public static void Main()
- {
- AppDomain apd = AppDomain.CreateDomain(“Rajendrs Domain”);
- MyAppDomain apdinfo = (MyAppDomain) apd.CreateInstanceAndUnwrap(Assembly.GetCallingAssembly()
- .GetName()
- .Name, “MyAppDomain”);
- Console.WriteLine(“Application Name = ” + apdinfo.GetInfo());
- }
- }