static void Main(string[] args) { Show1(); Console.WriteLine(DomainManagement.IsDeleted("TempDomain11")); Console.ReadKey(); }
public unsafe static string Test() { var dict2 = new Dictionary <int, string>(); var dict = new Dictionary <string, int>(); for (int i = 0; i < 10; i++) { dict[i.ToString()] = i; dict2[i] = i.ToString(); } var test = dict2.CustomerTree(item => item.ToString()); var temp = dict.HashTree(); var name = temp.GetType().Name; var result = temp["1"]; //var a = temp.GetKeys(1); //var domainName = temp.ProxyType.GetDomain().Name; Console.WriteLine(DomainManagement.IsDeleted(name)); // temp.Dispose(); for (int i = 0; i < 6; i++) { GC.Collect(); } return(name); }
static void Main(string[] args) { NatashaInitializer.Initialize(false); string text = @"namespace HelloWorld { public class Test { public Test(){ Name=""111""; } public string Name; public int Age{get;set;} } }"; //根据脚本创建动态类 AssemblyCSharpBuilder oop = new AssemblyCSharpBuilder("test"); oop.Domain = DomainManagement.Random; oop.Domain.AddReferencesFromDllFile(typeof(object).Assembly.Location); oop.Add(text); Type type = oop.GetTypeFromShortName("Test"); Console.WriteLine(type.Name); var action = NDelegate.UseDomain(oop.Domain).Action(""); var a = action.Method; Console.WriteLine(action.Method.Module.Assembly); Console.WriteLine(DomainManagement.IsDeleted(action.GetDomain().Name)); Console.ReadKey(); }
public static void CheckAlive() { for (int i = 0; i < count; i++) { if (!DomainManagement.IsDeleted("test" + i.ToString())) { Console.WriteLine($"{i} is aliave!"); } } }
public void Test3() { Assert.Equal("{\"Name\":\"11\"}", GetResult3()); for (int i = 0; i < 6; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); } Assert.False(DomainManagement.IsDeleted("TempDomain13")); }
public void Test2() { Assert.Equal("11", GetResult2()); for (int i = 0; i < 6; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); } Assert.True(DomainManagement.IsDeleted("TempDomain12")); }
public void Test1() { //Assert.Equal("Unable to connect to any of the specified MySQL hosts.",GetResult1()); GetResult1(); for (int i = 0; i < 6; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); } Assert.True(DomainManagement.IsDeleted("TempDADomain11")); }
public static void UnloadDelegate() { Assert.Equal(3, RunDelegate6()); #if !NETCOREAPP2_2 for (int i = 0; i < 6; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); } Assert.True(DomainManagement.IsDeleted("NDelegate6")); #endif }
public void Test1() { //ForTest1(); Assert.Equal("HelloTest", ForTest1()); #if !NETCOREAPP2_2 for (int i = 0; i < 10; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); } Assert.True(DomainManagement.IsDeleted("SingleDomainAsmTest1")); #endif }
public static int CheckAlive() { int tempCount = 0; for (int i = 0; i < count; i++) { if (!DomainManagement.IsDeleted("test" + i.ToString())) { tempCount++; Console.WriteLine($"{i} is aliave!"); } } return(tempCount); }
public static void Testqq() { Thread.Sleep(5000); TestMemoery(); for (int i = 0; (!DomainManagement.IsDeleted("TempDomain1")) && (i < 15); i++) { Console.WriteLine($"\t第{i}次!"); GC.Collect(); GC.WaitForPendingFinalizers(); Thread.Sleep(500); } //Testt(); Console.WriteLine(DomainManagement.IsDeleted("TempDomain1") ? "回收成功!" : "回收失败!"); }
static void Main(string[] args) { NatashaInitializer.InitializeAndPreheating(); var domainName = Test(); for (int i = 0; i < 6; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); } Console.WriteLine(domainName); Console.WriteLine(DomainManagement.IsDeleted(domainName)); Console.ReadKey(); }
static void Main(string[] args) { NatashaInitializer.Initialize(); string text = @"namespace HelloWorld { public class Test { public Test(){ Name=""111""; } public string Name; public int Age{get;set;} } }"; //根据脚本创建动态类 AssemblyCSharpBuilder oop = new AssemblyCSharpBuilder("test"); oop.Domain = DomainManagement.Random; //oop.Domain.AddReferencesFromDllFile(typeof(object).Assembly.Location); oop.Add(text); Type type = oop.GetTypeFromShortName("Test"); Console.WriteLine(type.Name); var action = NDelegate.UseDomain(oop.Domain).Action(""); var a = action.Method; Console.WriteLine(action.Method.Module.Assembly); Console.WriteLine(DomainManagement.IsDeleted(action.GetDomain().Name)); //var nClass = NClass // .RandomDomain(); //nClass.DelegateHandler. //type = NClass // .RandomDomain().Namespace("") // .Name("Test") // .Ctor(item => item // .Public() // .Body("Name = null;") // ) // .PublicField<string>("Name") // .GetType(); //type.Assembly //CSharpScript.EvaluateAsync Console.ReadKey(); }
public string Collection(string typeName) { for (int i = 0; i < 20; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); } if (DomainManagement.IsDeleted(typeName)) { return("Has Collection!"); } else { var a = DomainManagement.Get(typeName); a.Dispose(); } return("No Collection!"); }
public static void Testt() { Console.WriteLine("隔离编译动态方法:"); Console.WriteLine(); Show(); if (action != null) { Console.WriteLine("\t静态引用动态方法,增加方法代数!"); } //var a = AssmblyManagment.Remove("TempDomain"); Console.WriteLine(); Console.WriteLine(); Console.Write("第一次检测:"); Console.WriteLine(DomainManagement.IsDeleted("TempDomain") ? "回收成功!" : "回收失败!"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("启用GC回收方法!"); for (int i = 0; (!DomainManagement.IsDeleted("TempDomain")) && (i < 15); i++) { Console.WriteLine($"\t第{i}次!"); GC.Collect(); GC.WaitForPendingFinalizers(); Thread.Sleep(500); if (i == 6) { Console.WriteLine($"\t计数为{i},删除静态引用!"); //千万别再这里调用 AssemblyManagment.Get("TempDomain").Dispose(); action = null; } } Console.WriteLine(); Console.WriteLine(); //Console.WriteLine(!a.IsAlive? "回收成功!":"回收失败!"); Console.Write("第二次检测:"); Console.WriteLine(DomainManagement.IsDeleted("TempDomain") ? "回收成功!" : "回收失败!"); action?.Invoke(); }
public void Test2() { var domain = DomainManagement.Create("SingleDomainAsmTest2"); var assembly = domain.CreateAssembly("AsmTest1"); var @interface = assembly .CreateInterface("IAsmT1") .Using("System") .Public() .Body("string ShowMethod(string str);"); var @class = assembly .CreateClass("ClassAsm") .Using("System") .Public() .Inheritance("IAsmT1") .Method(method => method .Public() .DefinedName("ShowMethod") .Param <string>("str") .Body("return str+AsmEnum.Test.ToString();") .Return <string>() ); var @enum = assembly .CreateEnum("AsmEnum") .Public() .EnumField("Test") .EnumField("Test1") .EnumField("Test2", 1); var result = assembly.GetAssembly(); var type = assembly.GetTypeFromFullName(@class.NamespaceScript + "." + "ClassAsm"); domain.Remove(type.Assembly); assembly = domain.CreateAssembly("AsmTest2"); @interface = assembly .CreateInterface("IAsmT1") .Using("System") .Public() .Body("string ShowMethod(string str);"); @class = assembly .CreateClass("ClassAsm") .Using("System") .Public() .Inheritance("IAsmT1") .Method(method => method .Public() .DefinedName("ShowMethod") .Param <string>("str") .Body("return str+AsmEnum.Test.ToString()+\"1\";") .Return <string>() ); @enum = assembly .CreateEnum("AsmEnum") .Public() .EnumField("Test") .EnumField("Test1") .EnumField("Test2", 1); result = assembly.GetAssembly(); type = assembly.GetTypeFromFullName(@class.NamespaceScript + ".ClassAsm"); var builder = FastMethodOperator.DefaultDomain(); builder.AssemblyBuilder.Compiler.Domain = domain; var @delegate = builder.Using(type).Body(@" ClassAsm obj = new ClassAsm(); return obj.ShowMethod(""Hello""); ").Compile <Func <string, string> >(); Assert.Equal("HelloTest1", @delegate("hello")); #if !NETCOREAPP2_2 @delegate.DisposeDomain(); for (int i = 0; i < 10; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); } Assert.True(DomainManagement.IsDeleted("SingleDomainAsmTest1")); #endif }