CHAPTER 17 PROCESSES, APPDOMAINS, AND OBJECT CONTEXTS
}
// Make a new AppDomain.
MakeNewAppDomain();
Console.ReadLine();
private static void MakeNewAppDomain()
{
// Make a new AppDomain in the current process and
// list loaded assemblies.
AppDomain newAD = AppDomain.CreateDomain("SecondAppDomain");
ListAllAssembliesInAppDomain(newAD);
}
static void ListAllAssembliesInAppDomain(AppDomain ad)
{
// Now get all loaded assemblies in the default AppDomain.
var loadedAssemblies = from a in ad.GetAssemblies()
orderby a.GetName().Name select a;
}
}
Console.WriteLine("***** Here are the assemblies loaded in {0} *****\n",
ad.FriendlyName);
foreach (var a in loadedAssemblies)
{
Console.WriteLine("-> Name: {0}", a.GetName().Name);
Console.WriteLine("-> Version: {0}\n", a.GetName().Version);
}
If you run the current example, you will see that the default application domain
(CustomAppDomains.exe) has loaded mscorlib.dll, System.dll, System.Core.dll, and
CustomAppDomains.exe, given the C# code base of the current project. However, the new application
domain contains only mscorlib.dll, which as you recall, is the one .NET assembly that is always loaded
by the CLR for each and every application domain:
***** Fun with Custom AppDomains *****
***** Here are the assemblies loaded in CustomAppDomains.exe *****
-> Name: CustomAppDomains
-> Version: 1.0.0.0
-> Name: mscorlib
-> Version: 4.0.0.0
-> Name: System
-> Version: 4.0.0.0
-> Name: System.Core
-> Version: 4.0.0.0
642