|
Listing 22-2 extracted from chapter
.NET Remoting
Listing 22-1< > Listing 22-3
This listing can be compiled with the command line: csc.exe /out:MBVTest.exe /target:exe Example_22_2_to_rename_MBVTest.cs Errors: 0 Warnings: 0
Example_22_2_to_rename_MBVTest.cs
using System;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting;
using System.Threading;
[Serializable] // <- Added
public class Foo{ // : MarshalByRefObject <- Commented
public void DisplayInfo(string s) {
Console.WriteLine(s);
Console.WriteLine(" Name of the domain: " +
AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine(" ThreadID : " +
Thread.CurrentThread.ManagedThreadId);
}
}
public class Program {
static void Main() {
// obj1
Foo obj1 = new Foo();
obj1.DisplayInfo("obj1:");
Console.WriteLine(" IsObjectOutOfAppDomain(obj1)=" +
RemotingServices.IsObjectOutOfAppDomain(obj1));
Console.WriteLine(" IsTransparentProxy(obj1)=" +
RemotingServices.IsTransparentProxy(obj1));
// obj2
AppDomain appDomain=AppDomain.CreateDomain("Another AppDomain.");
Foo obj2 = (Foo)appDomain.CreateInstanceAndUnwrap(
"MBVTest", // Name of the assembly that contains the type.
"Foo"); // Name of the type.
obj2.DisplayInfo("obj2:"); // <- Here, the client is not aware
// that he is working with a transparent proxy.
Console.WriteLine(" IsObjectOutOfAppDomain(obj2)=" +
RemotingServices.IsObjectOutOfAppDomain(obj2));
Console.WriteLine(" IsTransparentProxy(obj2)=" +
RemotingServices.IsTransparentProxy(obj2));
}
}
Copyright Patrick Smacchia 2006 2007
|