.Net Runtime Library for Delphi
How to: Create an Application Domain

The common language runtime host creates application domains automatically when they are needed. However, you can create your own application domains and load into them those assemblies that you want to manage personally. You can also create application domains from which you execute code. You create a new application domain using one of the overloaded CreateDomain methods in the AppDomain interface TClrAppDomain class. You can give the application domain a name and reference it by that name.

The following example creates a new application domain, assigns it the name MyDomain, and then prints the name of the host domain and the newly created child application domain to the console.


program AppDomain1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, CNClrLib.Host, CNClrLib.Core; var Console: _Console; domain: TClrAppDomain; begin try Console := CoConsole.CreateInstance; try Console.WriteLine_14('Creating new AppDomain.'); domain := TClrAppDomain.CreateDomain('MyDomain'); Console.WriteLine_14('Host domain: ' + TClrAppDomain.GetCurrentDomain.FriendlyName); Console.WriteLine_14('child domain: ' + domain.FriendlyName); Console.ReadKey; finally Console := nil; end; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.