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 StartXMLSpy_Click and ShutdownXMLSpy_Click are those assigned to buttons in the AutomateXMLSpy 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\XMLSpy2019\

 

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

 

 

 

Starting XMLSpy

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

 

  // Handler for the "Start XMLSpy" button

      private void StartXMLSpy_Click(object sender, EventArgs e)

       {

          if (XMLSpy == null)

           {

              Cursor.Current = Cursors.WaitCursor;

 

              // If no XMLSpy instance is running, we create one and make it visible

               XMLSpy = new XMLSpyLib.Application();

               XMLSpy.Visible = true;

 

              Cursor.Current = Cursors.Default;

           }

          else

           {

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

              if (!XMLSpy.Visible)

                   XMLSpy.Visible = true;

           }

       }

 

 

 

Shutting down XMLSpy

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

 

 // Handler for the "Shutdown XMLSpy" button

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

      private void shutdownXMLSpy_Click(object sender, EventArgs e)

       {

          if (XMLSpy != null)

           {

              // Allow shutdown of XMLSpy by releasing the UI

               XMLSpy.Visible = false;

 

              // Explicitly release COM object

              try

               {

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

               }

              finally

               {

                  // Disallow subsequent access to this object

                   XMLSpy = null;

               }

           }

       }

 


© 2019 Altova GmbH