---------box程---------- 1.using System; 2.using System.Reflection; 3. 4.namespace AppDomain 5.{ 6. /// <summary> 7. /// Summary description for Class1. 8. /// </summary> 9. class MyAppDomain 10. { 11. /// <summary> 12. /// The main entry point for the application. 13. /// </summary> 14. [STAThread] 15. static void Main(string[] args) 16. { 17. // 18. // TODO: Add code to start application here 19. // 20. System.AppDomain objDomain = 21. System.AppDomain.CreateDomain("MyDomain"); 22. Console.WriteLine("Runtime Host Created Domain : {0}", 23. System.AppDomain.CurrentDomain.FriendlyName); 24. Console.WriteLine("My Domain : {0}", 25. objDomain.FriendlyName); 26. } 27. } 28.} ----------end---------- ---------box程---------- Runtime Host Created Domain : AppDomain.exe My Domain : MyDomain ----------end---------- ---------box程---------- 1.using System; 2.using System.Reflection; 3. 4.namespace AppDomain 5.{ 6. /// <summary> 7. /// Summary description for Class1. 8. /// </summary> 9. class MyAppDomain 10. { 11. /// <summary> 12. /// The main entry point for the application. 13. /// </summary> 14. [STAThread] 15. static void Main(string[] args) 16. { 17. // 18. // TODO: Add code to start application here 19. // 20. System.AppDomain objDomain = 21. System.AppDomain.CreateDomain("MyDomain"); 22. Console.WriteLine("Runtime Host Created Domain : {0}", 23. System.AppDomain.CurrentDomain.FriendlyName); 24. Console.WriteLine("My Domain : {0}", 25. objDomain.FriendlyName); 26. Console.WriteLine("---------Before----------"); 27. Console.WriteLine("Unload Application Domain"); 28. System.AppDomain.Unload(objDomain); 29. try 30. { 31. Console.WriteLine("---------After----------"); 32. Console.WriteLine("Runtime Host Created Domain : {0}", 33. System.AppDomain.CurrentDomain.FriendlyName); 34. Console.WriteLine("My Domain : {0}", 35. objDomain.FriendlyName); 36. } 37. catch(System.AppDomainUnloadedException e) 38. { 39. Console.WriteLine(e.Message); 40. } 41. } 42. } 43.} ----------end---------- ---------box程---------- Runtime Host Created Domain : AppDomain.exe My Domain : MyDomain ---------Before---------- Unload Application Domain ---------After---------- Runtime Host Created Domain : AppDomain.exe The target application domain has been unloaded. ----------end----------