Пример #1
0
        public void Precache()
        {
            DynamicMethod   method = new DynamicMethod("Db" + Guid.NewGuid().ToString(), typeof(CallModel), new Type[0]);
            ILGenerator     il     = method.GetILGenerator();
            ConstructorInfo ctor   = typeof(CallModel).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[0], null);

            il.Emit(OpCodes.Newobj, ctor);
            il.Emit(OpCodes.Ret);
            EmitFunc    = (Func <CallModel>)(method.CreateDelegate(typeof(Func <CallModel>)));
            NatashaFunc = CtorOperator.Create().NewDelegate <CallModel>();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Roslyn 预热;");
            var a = CtorOperator.NewDelegate <Program>();

            Console.WriteLine("3秒后开始编译;");
            Thread.Sleep(3000);
            Test();
            Console.WriteLine("请记录内存,5秒后开始释放;");
            Thread.Sleep(5000);
            Release();
            Console.WriteLine("请记录内存,5秒后开始回收;");
            Thread.Sleep(5000);
            RunGc();
            Console.WriteLine("存活检测,3秒后开始;");
            Thread.Sleep(3000);
            CheckAlive();
            Console.WriteLine("程序跑完!");
            Console.ReadKey();
        }