Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press

Buy directly from Paradoxal Press at $33.99 (Save 43%)



Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA


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