private void DelayedInit()
        {
            DTE dte = (DTE)GetService(typeof(DTE));

            if (dte == null)
            {
                // Usually this branch never executes but I want to make sure...
                PackageGlobals.BeginInvokeOnUIThread(DelayedInit);
                return;
            }

            m_VSMainWindow = new VSMainWindow();
            m_VSMainWindow.Initialize((IntPtr)dte.MainWindow.HWnd);
            m_VSMainWindow.OnWindowTitleUpdateNeeded += m_VSMainWindow_OnWindowTitleUpdateNeeded;

            m_UpdateTimer          = new System.Windows.Forms.Timer();
            m_UpdateTimer.Tick    += UpdateTimer_Tick;
            m_UpdateTimer.Interval = UPDATE_PERIOD_MILLISECS;
            m_UpdateTimer.Start();

            IVsSolution vs_solution = (IVsSolution)GetService(typeof(IVsSolution));

            vs_solution.AdviseSolutionEvents(this, out m_SolutionEventsCookie);

            IVsDebugger debugger = (IVsDebugger)GetService(typeof(IVsDebugger));

            debugger.AdviseDebuggerEvents(this, out m_DebuggerEventsCookie);

            PackageGlobals.InitInstance(this);

            m_PrevVariableValues = PackageGlobals.Instance().CreateFreshEvalContext().VariableValues;

            m_ExpressionCompilerThread = new ExpressionCompilerThread();
            // During normal use the expression doesn't change except when configuring so a cache size of 1 does the job quite well.
            // Usually what changes is the variables.
            m_CompiledExpressionCache = new CompiledExpressionCache(PackageGlobals.Instance().ExecFuncEvaluator, PackageGlobals.Instance().CompileTimeConstants, 1);

            UpdateWindowTitle();
        }
        private void UpdateWindowTitle()
        {
            m_VSMainWindow.Update();

            PackageGlobals globals           = PackageGlobals.Instance();
            EvalContext    eval_ctx          = globals.CreateFreshEvalContext();
            bool           variables_changed = !CompareVariables(eval_ctx.VariableValues, m_PrevVariableValues);

            if (variables_changed)
            {
                m_PrevVariableValues = eval_ctx.VariableValues;
                globals.TitleSetupEditor.Variables = eval_ctx.VariableValues;
            }

            ToolOptions options = (ToolOptions)GetDialogPage(typeof(ToolOptions));

#if VS2010_AND_LATER
            if (m_DebugPrintTitleControlHierarchyCount < 5 && options.Debug)
            {
                ++m_DebugPrintTitleControlHierarchyCount;
                m_VSMainWindow.DebugPrintTitleControlHierarchy();
            }
#endif

            PackageGlobals.VSMultiInstanceInfo multi_instance_info;
            globals.GetVSMultiInstanceInfo(out multi_instance_info);

            bool extension_active;
            switch (options.ExtensionActivationRule)
            {
            case EExtensionActivationRule.ActiveWithMultipleVSInstances:
                extension_active = multi_instance_info.multiple_instances;
                break;

            case EExtensionActivationRule.ActiveWithMultipleVSInstancesOfTheSameVersion:
                extension_active = multi_instance_info.multiple_instances_same_version;
                break;

            case EExtensionActivationRule.AlwaysInactive:
                extension_active = false;
                break;

            default:
                extension_active = true;
                break;
            }

            if (extension_active)
            {
                TitleSetup title_setup = globals.TitleSetup;
                if (m_ExpressionContainsExec || variables_changed || m_PrevExtensionActivationRule != options.ExtensionActivationRule ||
                    title_setup.TitleExpression != m_PrevTitleExpressionStr)
                {
                    Parser parser             = new Parser(title_setup.TitleExpression, globals.ExecFuncEvaluator, globals.CompileTimeConstants);;
                    ExpressionCompilerJob job = new ExpressionCompilerJob(parser, globals.CreateFreshEvalContext(), false, m_CompiledExpressionCache);
                    job.OnCompileFinished += OnCompileFinished;
                    m_ExpressionCompilerThread.RemoveAllJobs();
                    m_ExpressionCompilerThread.AddJob(job);
                }
                m_PrevTitleExpressionStr = title_setup.TitleExpression;
            }
            else
            {
                m_VSMainWindow.SetTitle(m_VSMainWindow.OriginalTitle);
            }

            m_PrevExtensionActivationRule = options.ExtensionActivationRule;
        }