The ExecuteAssembly method of the AppDomain class belonging
to the System namespace is used to execute an assembly in an Application
Domain. The following are the overloaded versions of the ExecuteAssembly
method.
Listing 3
public int ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
public int ExecuteAssembly(String assemblyFile, Evidence assemblySecurity)
public int ExecuteAssembly(String assemblyFile)
The following is the source code given to illustrate how we
can execute a remote assembly in an Application Domain.
Listing 4
using System;
using System.Runtime.Remoting;
using System.Reflection;
public class ExecuteAssemblyApplication
{
public static void Main( String[] args )
{
AppDomain appDomain = AppDomain.CreateDomain("RemoteDomain");
appDomain.ExecuteAssembly(@"C:\Test.exe");
appDomain. CreateInstanceFrom(@"C:\Test.exe", " ExecuteAssembly.Test");
//Some code
AppDomain.Unload(appDomain);
}
}
}
The following is the source code for the Welcome class of
the Welcome.exe assembly that has been used in the previous listing.
Listing 5
using System;
using System.Threading;
namespace ExecuteAssembly
{
public class Test
{
public static void Main(String[] args)
{
Console.WriteLine("Application Domain: " + Thread.GetDomain().Name);
}
}
}