Esempio n. 1
0
        private void ShutdownAddIn()
        {
            var currentDomain = AppDomain.CurrentDomain;

            try
            {
                _logger.Log(LogLevel.Info, "Rubberduck is shutting down.");
                _logger.Log(LogLevel.Trace, "Unhooking VBENativeServices events...");
                VBENativeServices.UnhookEvents();

                _logger.Log(LogLevel.Trace, "Broadcasting shutdown...");
                User32.EnumChildWindows(_ide.MainWindow.Handle(), EnumCallback, new IntPtr(0));

                _logger.Log(LogLevel.Trace, "Releasing dockable hosts...");
                Windows.ReleaseDockableHosts();

                if (_app != null)
                {
                    _logger.Log(LogLevel.Trace, "Initiating App.Shutdown...");
                    _app.Shutdown();
                    _app = null;
                }

                if (_kernel != null)
                {
                    _logger.Log(LogLevel.Trace, "Disposing IoC container...");
                    _kernel.Dispose();
                    _kernel = null;
                }

                _isInitialized = false;
                _logger.Log(LogLevel.Info, "No exceptions were thrown.");
            }
            catch (Exception e)
            {
                _logger.Error(e);
                _logger.Log(LogLevel.Warn, "Exception is swallowed.");
                //throw; // <<~ uncomment to crash the process
            }
            finally
            {
                _logger.Log(LogLevel.Trace, "Unregistering AppDomain handlers....");
                currentDomain.AssemblyResolve    -= LoadFromSameFolder;
                currentDomain.UnhandledException -= HandlAppDomainException;
                _logger.Log(LogLevel.Trace, "Done. Initiating garbage collection...");
                GC.Collect();
                _logger.Log(LogLevel.Trace, "Done. Waiting for pending finalizers...");
                GC.WaitForPendingFinalizers();
                _logger.Log(LogLevel.Trace, "Done. Shutdown completed. Quack!");
                _isInitialized = false;
            }
        }
Esempio n. 2
0
        private void ShutdownAddIn()
        {
            var currentDomain = AppDomain.CurrentDomain;

            try
            {
                _logger.Log(LogLevel.Info, "Rubberduck is shutting down.");
                _logger.Log(LogLevel.Trace, "Unhooking VBENativeServices events...");
                VBENativeServices.UnhookEvents();

                _logger.Log(LogLevel.Trace, "Releasing dockable hosts...");
                Windows.ReleaseDockableHosts();

                if (_app != null)
                {
                    _logger.Log(LogLevel.Trace, "Initiating App.Shutdown...");
                    _app.Shutdown();
                    _app = null;
                }

                if (_container != null)
                {
                    _logger.Log(LogLevel.Trace, "Disposing IoC container...");
                    _container.Dispose();
                    _container = null;
                }
            }
            catch (Exception e)
            {
                _logger.Error(e);
                _logger.Log(LogLevel.Warn, "Exception is swallowed.");
                //throw; // <<~ uncomment to crash the process
            }
            finally
            {
                try
                {
                    _logger.Log(LogLevel.Trace, "Disposing COM safe...");
                    ComSafeManager.DisposeAndResetComSafe();
                    _addin = null;
                    _ide   = null;

                    _isInitialized = false;
                    _logger.Log(LogLevel.Info, "No exceptions were thrown.");
                }
                catch (Exception e)
                {
                    _logger.Error(e);
                    _logger.Log(LogLevel.Warn, "Exception disposing the ComSafe has been swallowed.");
                    //throw; // <<~ uncomment to crash the process
                }
                finally
                {
                    _logger.Log(LogLevel.Trace, "Unregistering AppDomain handlers....");
                    currentDomain.AssemblyResolve    -= LoadFromSameFolder;
                    currentDomain.UnhandledException -= HandlAppDomainException;
                    _logger.Log(LogLevel.Trace, "Done. Main Shutdown completed. Toolwindows follow. Quack!");
                    _isInitialized = false;
                }
            }
        }