|
Listing 22-1 extracted from chapter
.NET Remoting
Listing 21-22< > Listing 22-2
This listing can be compiled with the command line: csc.exe /out:MBRTest.exe /target:exe Example_22_1_to_rename_MBRTest.cs Errors: 0 Warnings: 0
Example_22_1_to_rename_MBRTest.cs
using System;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting;
using System.Threading;
public class Foo : MarshalByRefObject {
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(
"MBRTest", // 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
|