Creating Custom App Domain C# with Example



Creating Custom App Domain C# with Example

 using System;
using System.Linq;

namespace CSharpMultiThreading
{
	class CustomApplicationDomain
	{
		static void Main(string[] args)
		{
			// Show all loaded assemblies in default AppDomain.
			AppDomain defaultAD = AppDomain.CurrentDomain;
			ListAllAssembliesInAppDomain(defaultAD);
			
			// 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} *****", ad.FriendlyName);
			
			foreach (var a in loadedAssemblies)
			{
				Console.WriteLine("-> Name: {0}", a.GetName().Name);
				Console.WriteLine("-> Version: {0}\n", a.GetName().Version);
			}
		}
	}
}
 

0 Comment's

Comment Form