Example #1
0
        private void CleanupHostSide()
        {
            if (!m_isHostSideDirty)
            {
                return;
            }

            lock (m_hostSideLock)
            {
                //Debug.Assert(HostSide != null);

                if (HostSide != null)
                {
                    try
                    {
                        ((ITestAdapter)HostSide).Cleanup();
                    }
                    catch (Exception ex)    // We don't know what this can throw in advance.
                    {
                        SendResult(Resources.FailedToCallTACleanup(ex), TestOutcome.Warning);
                    }
                }

                // m_runConfig can be null if cleanup is called too early, i.e. before we completed init.
                if (m_runConfig != null && m_runConfig.IsExecutedUnderDebugger)
                {
                    // Detach debugger for VS we are going to shut down.
                    //Debug.Assert(m_hostSession != null);
                    if (m_hostSession != null)
                    {
                        try
                        {
                            // Detach debugger but keep HostSession alive for possible attach to restarted VS.
                            m_hostSession.DetachDebugger(m_vsIde.Process.Id);
                        }
                        catch (Exception ex)
                        {
                            SendResult(Resources.FailedToDetachDebugger(ex), TestOutcome.Warning);
                        }
                    }
                }

                if (m_vsIde != null)
                {
                    try
                    {
                        m_vsIde.Dispose();
                    }
                    catch (Exception ex)
                    {
                        SendResult(Resources.ErrorShuttingDownVS(ex), TestOutcome.Warning);
                    }
                }
                m_vsIde           = null;
                m_hostSide        = null;
                m_isHostSideDirty = false;
            }
        }