logo
CSharp_Prog_Guide

Общие сведения о доменах приложений

Домены приложений обладают следующими свойствами:

Executing Code in Another Application Domain

Once an assembly has been loaded into an application domain, the code it contains can be executed. The simplest way to do this is to use AssemblyLoad which will load the assembly into the current application domain, and begin running the code at the assembly's default entry point.

If you want to load the assembly into another application domain, use ExecuteAssembly or ExecuteAssemblyByName, or one of the other overloaded versions of these methods.

If you want to execute the other assembly starting other than at the default entry point, define a new type in the remote assembly, deriving from MarshalByRefObject. Then use CreateInstance to create an instance of that type in your application.

Consider the following file, which creates an assembly consisting of a single namespace and two classes. Assume this assembly has been built, and is stored on drive C with the name HelloWorldRemote.exe.

// This namespace contains code to be called.

namespace HelloWorldRemote

{

public class RemoteObject : System.MarshalByRefObject

{

public RemoteObject()

{

System.Console.WriteLine("Hello, World! (RemoteObject Constructor)");

}

}

class Program

{

static void Main()

{

System.Console.WriteLine("Hello, World! (Main method)");

}

}

}