Altova XMLSpy 2024 Enterprise Edition

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# subfolder of the API Examples folder (see the file Form1.cs):

 

 

Windows 7, Windows 8, Windows 10, Windows 11

C:\Users\<username>\Documents\
Altova\XMLSpy\2024\Examples

 

You can compile and run the project from within Visual Studio 2012/2013/2015/2017/2019/2022.

 

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;

               }

           }

       }

 

© 2017-2023 Altova GmbH