Exemple #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);
                };

                Factory.invocationDelegate.DynamicInvoke(del);

                AppDomain.Unload(Factory.operatingDomain);

                foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
                {
                    if (module.ModuleName == PechkinBindings.LibFilename)
                    {
                        while (PechkinBindings.FreeLibrary(module.BaseAddress))
                        {
                        }
                    }
                }

                Factory.operatingDomain = null;
            }

            if (Factory.synchronizer != null)
            {
                Factory.synchronizer.Terminate();
                Factory.synchronizer = null;
            }
        }
Exemple #2
0
        /// <summary>
        /// Deinitializes library.
        /// </summary>
        public static void DeinitLib()
        {
            if (!_inited)
            {
                return;
            }
            _inited = false;

            LibDeInit?.Invoke();

            if (Log.IsTraceEnabled)
            {
                Log.Trace("T:" + Thread.CurrentThread.Name + " Deinitializing library (wkhtmltopdf_deinit)");
            }

            PechkinBindings.wkhtmltopdf_deinit();

            _hackObj = null;
        }