static void Main() { Console.WriteLine("Test_AppDomain_07 : test of life time service with Test_AppDomain_05.dll"); AppDomain domain = AppDomain.CreateDomain("New Domain"); Console.WriteLine("set initial lease time to 10 sec"); LifetimeServices.LeaseTime = TimeSpan.FromSeconds(10); // This is the InitialLeaseTime property Console.WriteLine(); DateTime dt1 = DateTime.Now; itest_01 test02 = (itest_01)domain.CreateInstanceFromAndUnwrap("Test_AppDomain_05.dll", "Test_AppDomain_05.test_02"); itest_01 test03 = (itest_01)domain.CreateInstanceFromAndUnwrap("Test_AppDomain_05.dll", "Test_AppDomain_05.test_03"); Console.WriteLine("{0:HH:mm:ss} create object Test_AppDomain_05.test_02 and Test_AppDomain_05.test_03", dt1); Console.WriteLine(); DateTime dt2; //Console.WriteLine("wait 15 sec"); //Thread.Sleep(15000); //dt2 = DateTime.Now; //Console.WriteLine("{0:HH:mm:ss}-{1} test_03.GetMessage() : {2}", dt2, TimeSpanToString(dt2.Subtract(dt1)), test03.GetMessage()); //Console.WriteLine("wait 2 min"); //Thread.Sleep(120000); //dt2 = DateTime.Now; //Console.WriteLine("{0:HH:mm:ss}-{1} test_03.GetMessage() : {2}", dt2, TimeSpanToString(dt2.Subtract(dt1)), test03.GetMessage()); Console.WriteLine("wait 6 min"); Thread.Sleep(360000); //Console.WriteLine("wait 10 min"); //Thread.Sleep(600000); //Console.WriteLine("wait 30 min"); //Thread.Sleep(1800000); //Console.WriteLine("wait 2h"); //Thread.Sleep(7200000); dt2 = DateTime.Now; Console.WriteLine("{0:HH:mm:ss}-{1} test_02.GetMessage() : {2}", dt2, TimeSpanToString(dt2.Subtract(dt1)), test02.GetMessage()); Console.WriteLine("{0:HH:mm:ss}-{1} test_03.GetMessage() : {2}", dt2, TimeSpanToString(dt2.Subtract(dt1)), test03.GetMessage()); //for (int i = 0; i < 500; i++) //{ // Thread.Sleep(1000); // DateTime dt2 = DateTime.Now; // Console.WriteLine("{0,6} {1:HH:mm:ss}-{2} test_03.GetMessage() : {3}", i + 1, dt2, TimeSpanToString(dt2.Subtract(dt1)), test03.GetMessage()); //} AppDomain.Unload(domain); }
static void Main() { Console.WriteLine("Test_AppDomain_05 : test loading dll in a domain use of AppDomain.CreateInstanceFromAndUnwrap"); Console.WriteLine("Create domain \"Test domain\""); AppDomain domain = AppDomain.CreateDomain("Test domain"); Console.WriteLine("Create instance from \"Test_AppDomain_05.dll\", \"Test_AppDomain_05.test_01\""); object test01 = domain.CreateInstanceFromAndUnwrap("Test_AppDomain_05.dll", "Test_AppDomain_05.test_01"); itest_01 itest01 = (itest_01)test01; itest_02 itest02 = (itest_02)test01; Console.WriteLine("test01.GetMessage() \"{0}\"", itest01.GetMessage()); Console.WriteLine("test01.GetCallingAssembly() \"{0}\"", itest02.GetCallingAssembly()); Console.WriteLine("test01.GetCallingAssemblyProduct() \"{0}\"", itest02.GetCallingAssemblyProduct()); Console.WriteLine("test01.GetEntryAssembly() \"{0}\"", itest02.GetEntryAssembly()); Console.WriteLine("test01.GetExecutingAssembly() \"{0}\"", itest02.GetExecutingAssembly()); Console.WriteLine("test01.GetExecutingAssemblyProduct() \"{0}\"", itest02.GetExecutingAssemblyProduct()); Console.WriteLine("test01.GetApplicationCompany() \"{0}\"", itest02.GetApplicationCompany()); Console.WriteLine("Unload domain \"Test domain\""); AppDomain.Unload(domain); }