首页 > 解决方案 > 在窗体类中单击按钮后如何执行加载项类中的代码?

问题描述

我有这个代码与我的 Form1 类代码并行运行。从我的 Form 类中单击一个按钮后, Global.Launcher 变成了一个真实的声明。当我运行此代码时,由于无限循环,我无法单击 Project(基本冻结)上的加载项(按钮所在的位置),因为我无法访问该按钮。有解决方法吗?简而言之,在按下加载项表单上的按钮之前,我不想运行此类中的任何代码。提前致谢。

    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            this.Application.NewProject += new Microsoft.Office.Interop.MSProject._EProjectApp2_NewProjectEventHandler(Application_NewProject);

            void Application_NewProject(Microsoft.Office.Interop.MSProject.Project pj)
            {
                while(Global.launcher == false)
                {
                }
                System.Diagnostics.Debug.WriteLine("Starting to run code: ");
            }

        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}

标签: c#.netproject

解决方案


推荐阅读