asp net 3.5unleashed

Page 471

// Call a method on this object. The proxy remotes // the call to the other AppDomain. mbrt.SomeMethod(Thread.GetDomain().FriendlyName);

// I’m done using the other AppDomain, so // I’ll unload it and all its assemblies. AppDomain.Unload(ad);

// Try to call a method on the other AppDomain’s object. // The object was destroyed when the AppDomain was unloaded , // so an exception is thrown. try { mbrt.SomeMethod(Thread.GetDomain().FriendlyName);

// The following line should NOT be displayed. Console.WriteLine( "Called SomeMethod on object in other AppDomain.\n" + "This shouldn’t happen."); } catch (AppDomainUnloadedException) { // I’ll catch the exception here, and the // following line should be displayed. Console.WriteLine( "Fail to call SomeMethod on object in other AppDomain .\n" + "This should happen."); }

Console.ReadLine(); } }

// This type is derived from MarshalByRefObject. class MarshalByRefType : MarshalByRefObject {

// This instance method can be called via a proxy. public void SomeMethod(String sourceAppDomain) {


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.