Exemplo n.º 1
0
        static void ProcessCalculator(out WeakReference weakReference)
        {
            var assemblyPath = @"C:\Users\ОралбаевГ\source\repos\Calc\Calc\bin\Debug\netcoreapp3.0\Calc.dll";
            var context      = new CalculatorAssemblyLoadContext();

            var calculatorAssembly = context.LoadFromAssemblyPath(assemblyPath);

            weakReference = new WeakReference(context, true);

            var currentDomain = AppDomain.CurrentDomain;

            Console.WriteLine("*******************************************************************************************************************");
            foreach (var assembly in currentDomain.GetAssemblies())
            {
                Console.WriteLine(assembly.GetName());
            }

            var args = new object[] { new string[] { "1", "5" } };

            calculatorAssembly.EntryPoint.Invoke(null, args);

            context.Unload();
        }
        static void ProcessCalculator(out WeakReference weakReference)
        {
            var assemblyPath       = @"C:\Users\ЕсентайА\source\repos\Calculator\Calculator\bin\Debug\netcoreapp3.0\Calculator.dll";
            var context            = new CalculatorAssemblyLoadContext(assemblyPath);
            var calculatorAssembly = context.LoadFromAssemblyPath(assemblyPath);

            weakReference = new WeakReference(context, true);
            var currentDomain = AppDomain.CurrentDomain;

            Console.WriteLine("************************************");
            for (int i = 0; weakReference.IsAlive && (i < 10); i++)
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            foreach (var assembly in currentDomain.GetAssemblies())
            {
                Console.WriteLine($"{assembly.GetName()}");
            }
            var args = new object[] { new string[] { "1", "5" } };

            calculatorAssembly.EntryPoint.Invoke(null, args);
            context.Unload();
        }