Creates a new instance of the specified type.
using System;
using System.Reflection;
public class Worker : MarshalByRefObject
{
public void PrintDomain()
{
Console.WriteLine("Object is executing in AppDomain \"{0}\"",AppDomain.CurrentDomain.FriendlyName);
}
}
class Example
{
public static void Main()
{
Worker localWorker = new Worker();
localWorker.PrintDomain();
AppDomain ad = AppDomain.CreateDomain("New domain");
Worker remoteWorker = (Worker) ad.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName,"Worker");
remoteWorker.PrintDomain();
}
}
Related examples in the same category