I am a beginner in C# and I was studying a C# text book regarding AppDomain.
This is what I found in a text book "C# 4.0 in a Nutshell 4e (O'Reilly)"
Let’s revisit the most basic multidomain scenario:
static void Main()
{
AppDomain newDomain = AppDomain.CreateDomain ("New Domain");
newDomain.ExecuteAssembly ("test.exe");
AppDomain.Unload (newDomain);
}
Calling ExecuteAssembly on a separate domain is convenient but offers little opportunity
to interact with the domain. It also requires that the target assembly is an
executable, and it commits the caller to a single entry point. The only way to incorporate
flexibility is to resort to an approach such as passing a string of arguments to
the executable.
powerful approach is to use AppDomain’s DoCallBack method.
This executes on another application domain, a method on a given type. The type’s assembly is automatically loaded into the domain (the CLR will know where it lives if the current domain can reference it). In the following example, a method in the currently executing class is run in a new domain:
class Program
{
static void Main()
{
AppDomain newDomain = AppDomain.CreateDomain ("New Domain");
newDomain.DoCallBack (new CrossAppDomainDelegate (SayHello));
AppDomain.Unload (newDomain);
}
static void SayHello()
{
Console.WriteLine ("Hi from " + AppDomain.CurrentDomain.FriendlyName);
}
}
Here, SayHello() method is present in the same Program class. By the statement,
"The type’s assembly is automatically loaded into the domain (the CLR will know where it lives if the current domain can reference it)."
This means, if SayHello() method is present in some other third party assembly, then also that assembly is loaded? I did not understand this statement. Can you please help me in this? Thank you.