Ejemplo n.º 1
0
        public void Dispose()
        {
            // Dispose of packages while the UI thread is still running, it's
            // possible some packages may need to get back onto the UI thread
            // before their Dispose is complete.  TaskProvider does this - it wants
            // to wait for the task provider thread to exit, but the same thread
            // maybe attempting to get back onto the UI thread.  If we yank out
            // the UI thread first then it never makes it over and we just hang
            // and deadlock.
            foreach (var package in _loadedPackages)
            {
                package.Dispose();
            }

            _monSel.UnadviseSelectionEvents(_monSelCookie);
            Shell.SetProperty((int)__VSSPROPID6.VSSPROPID_ShutdownStarted, true);
            _serviceProvider.Dispose();
            Container.Dispose();
            _shutdown = true;
            _uiEvent.Set();
            if (!UIThread.Join(TimeSpan.FromSeconds(30)))
            {
                Console.WriteLine("Failed to wait for UI thread to terminate");
            }
            ThrowPendingException();
            AssertListener.ThrowUnhandled();
        }