Common Language Runtime

Common language runtime :What is application domain?

Common language run time establishes a boundary around objects created within the same application scope. All objects which belong to the same application or website are kept in the memory isolated from the other application so that they do not conflict with each other resulting in corruption of data. For example a variable “x” created in the application “Bank_app” is distinguished from the variable “x”  in the application “Employee_app” .

CLR help isolate objects created in one application from those created in other applications so that run-time behavior is predictable and the variables do not display garbage value ( which is common in C/C++).

Application Domain:

Application domains provide a flexible and secure method of isolating running applications. An application domain provides application security by the common language runtime  to provide isolation between applications. Several processes which need to communicate with each other can be executed in the same process and can be accessed without switching between processes. The ability to run multiple applications within a single process increases server scalability and efficiency of the server. Using application domains ensures that code running in one domain cannot affect other applications in the process.

In the example below an application domain called “MyDomain “ is created and two applications are launched in the same domain .

  • The first application is an employee windows application for adding and retrieval of data from the employee database named “empproj”
  • The second application named “consoleadd”  is a console application which prints the sum of two long integers .Both the applications have been compiled independently and executed before to create an .exe file.

Then with the help of the following C# code an application domain is created and multiple applications are loaded into the same application domain and executed.

using System;

namespace ConsoleApplication1
{
public class AppDomain1
{
public static void Main()
{
Console.WriteLine(“Creating new AppDomain.”);
AppDomain domain = AppDomain.CreateDomain(“MyDomain”);

Console.WriteLine(“Host domain: ” + AppDomain.CurrentDomain.FriendlyName);//prints parent domain name
Console.WriteLine(“child domain: ” + domain.FriendlyName);//prints child domain name
domain.ExecuteAssembly(@”C:\Users\Indrani Sen\Documents\Visual Studio 2008\Projects\Empproj\Empproj\bin\Debug\Empproj.exe”);
domain.ExecuteAssembly(@”C:\Users\Indrani Sen\Documents\Visual Studio 2008\Projects\consoleadd\consoleadd\bin\Debug\consoleadd.exe”);

Console.ReadLine();

}
}

}

appdomain
appdomain

Application domain