Illustrates unloading an application domain
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy
Publisher: Sybex;
ISBN: 0782129110
*/
/*
Example18_4.cs illustrates unloading an application domain
*/
using System;
using System.Runtime.Remoting;
using System.Reflection;
public class Example18_4
{
public static void Main()
{
// create a new appdomain
AppDomain d = AppDomain.CreateDomain("NewDomain");
// load an instance of the SimpleObject class
ObjectHandle hobj = d.CreateInstance("Example18_2", "SimpleObject");
// use a local variable to access the object
SimpleObject so = (SimpleObject) hobj.Unwrap();
Console.WriteLine(so.ToUpper("make this uppercase"));
// unload the application domain
AppDomain.Unload(d);
Console.WriteLine(so.ToUpper("make this uppercase"));
}
}
//===================================================
/*
Example18_2.cs defines a simple object to create
*/
using System;
[Serializable]
public class SimpleObject
{
public String ToUpper(String inString)
{
return(inString.ToUpper());
}
}
Related examples in the same category