C# Startup and Shutdown hookup

 

VB and C# hook into events very differently.  A VB template can use “Handles Me.Startup” and Handles Me.Shutdown” in the AppAddIn.vb file to hookup the events.  C# requires this code to be explicitly executed, so you’ll need to add some hookup code.  This is done in the ShapeAppCSharp samples by using an InternalStartup method (see below) but you could add the code to your OnStartup method.

 

ShapeAppCSharp sample:

AppAddIn.designer.cs file

        protected override void FinishInitialization() {

            base.FinishInitialization();

            this.OnStartup();

            this.InternalStartup();

            if ((this.Startup != null)) {

                this.Startup(this, System.EventArgs.Empty);

            }

        }

 

AppAddIn.cs file

        private void InternalStartup()

        {

            this.Startup += new System.EventHandler(AppAddIn_Startup);

            this.Shutdown += new System.EventHandler(AppAddIn_Shutdown);

        }

 

 

You could do this instead:

        void VSTAIntegration.ISimpleEntryPoint.OnStartup()

        {

            this.Startup += new System.EventHandler(AppAddIn_Startup);      //added hookup for Startup

            this.Shutdown += new System.EventHandler(AppAddIn_Shutdown);    //added hookup for Shutdown

 

            if (this.Startup != null)

            {

                this.VSTAApplication.BeforeLogOn += Application_BeforeLogOn;

}

 

 


Posted May 22 2009, 03:50 PM by BillL
Filed under: , ,
Copyright Summit Software Company, 2008. All rights reserved.