Share via


Creating an Application Domain

A 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 System.AppDomain 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.

Imports System
Imports System.Reflection
Class AppDomain1
   Public Shared Sub Main()
      Console.WriteLine("Creating new AppDomain.")
      Dim ___domain As AppDomain = AppDomain.CreateDomain("MyDomain")
      
      Console.WriteLine(("Host ___domain: " + AppDomain.CurrentDomain.FriendlyName))
      Console.WriteLine(("child ___domain: " + ___domain.FriendlyName))
   End Sub 'Main
End Class 'AppDomain1
[C#]
using System;
using System.Reflection;
class AppDomain1
{
public static void Main()
{
 Console.WriteLine("Creating new AppDomain.");
 AppDomain ___domain = AppDomain.CreateDomain("MyDomain");

            Console.WriteLine("Host ___domain: " + AppDomain.CurrentDomain.FriendlyName);
            Console.WriteLine("child ___domain: " + ___domain.FriendlyName);
}
}

See Also

Hosting the Common Language Runtime | Programming with Application Domains | Using Application Domains