Ejemplo n.º 1
0
        /// <summary>
        /// Unloads the private AppDomain and the wkhtmltopdf library, and if applicable, destroys
        /// the synchronization thread.
        /// </summary>
        /// <param name="sender">Typically a null value, not used in the method.</param>
        /// <param name="e">Typically EventArgs.Empty, not used in the method.</param>
        private static void TearDownAppDomain(object sender, EventArgs e)
        {
            if (Factory.operatingDomain != null)
            {
                Func <object> del = () =>
                {
                    Factory.operatingDomain.DoCallBack(() => PechkinBindings.wkhtmltopdf_deinit());

                    return(null);
                };

                SynchronizedDispatcher.Invoke(del);

                AppDomain.Unload(Factory.operatingDomain);

                foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
                {
                    if (module.ModuleName == "wkhtmltox.dll")
                    {
                        while (WinApiHelper.FreeLibrary(module.BaseAddress))
                        {
                        }
                    }
                }

                Factory.operatingDomain = null;
            }

            SynchronizedDispatcher.Terminate();
        }
Ejemplo n.º 2
0
        private void TearDownAppDomain(object sender, EventArgs e)
        {
            if (remoteDomain == null)
            {
                return;
            }

            OnBeforeUnload((ActionShim)(() => NestedToolset.Unload()));

            AppDomain.Unload(remoteDomain);

            var expected = Path.Combine(
                Deployment.Path,
                WkhtmltoxBindings.DLLNAME);

            foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
            {
                if (module.FileName == expected)
                {
                    while (WinApiHelper.FreeLibrary(module.BaseAddress))
                    {
                    }

                    break;
                }
            }

            remoteDomain = null;
            Loaded       = false;

            if (Unloaded != null)
            {
                Unloaded(this, EventArgs.Empty);
            }
        }