Application Startup and Shutdown

www.altova.com Imprimir este apartado Página anterior Subir un nivel Página siguiente

Inicio >  Referencia del programador > Application API > Overview > Programming Languages > C# >

Application Startup and Shutdown

In the code snippets below, the methods StartStyleVision_Click and ShutdownStyleVision_Click are those assigned to buttons in the AutomateStyleVision example that, respectively, start up and shut down the application. This example is located in the C# folder of the API Examples folder (see the file Form1.cs):

 

Windows 7, Windows 8, Windows 10

C:\Users\<usuario>\Documentos\
Altova\StyleVision2019\StyleVision

 

You can compile and run the project from within Visual Studio 2008 or Visual Studio 2010.

 

 

 

Starting StyleVision

The following code snippet from the AutomateStyleVision example shows how to start up the application.

 

  // Handler for the "Start StyleVision" button

      private void StartStyleVision_Click(object sender, EventArgs e)

       {

          if (StyleVision == null)

           {

              Cursor.Current = Cursors.WaitCursor;

 

              // If there is no StyleVision instance, create one and make it visible.

               StyleVision = new StyleVisionLib.Application();

               StyleVision.Visible = true;

 

              Cursor.Current = Cursors.Default;

           }

          else

           {

              // If an instance of StyleVision is already running, make sure it's visible

              if (!StyleVision.Visible)

                   StyleVision.Visible = true;

           }

       }

 

 

 

Shutting down StyleVision

The following code snippet from the AutomateStyleVision example shows how to shut down the application.

 

 // Handler for the "Shutdown StyleVision" button

      // Shut down the application instance by explicitly releasing the COM object.

      private void shutdownStyleVision_Click(object sender, EventArgs e)

       {

          if (StyleVision != null)

           {

              // Allow shut-down of StyleVision by releasing UI

               StyleVision.Visible = false;

 

              // Explicitly release the COM object

              try

               {

                  int i = System.Runtime.InteropServices.Marshal.ReleaseComObject(StyleVision);

                  while (System.Runtime.InteropServices.Marshal.ReleaseComObject(StyleVision) > 0) ;

               }

              finally

               {

                  // Disallow subsequent access to this object.

                   StyleVision = null;

               }

           }

       }

 


© 2019 Altova GmbH