Stopping Solidworks

Looking for help re: terminating SolidWorks at the end of programexecution. According to the API documentation under UserControl:

If the SolidWorks application isstarted by your program, then the SolidWorks application closeswhen your program ends. However, if you pass control of theSolidWorks application to the end-user, then it remains runningafter your program ends.

I've found this to be inconsistent and if theprogram errors, SolidWorks will continue to run (we do not haveUserControl = true). Using Sldworks.Closedoc will not work when theSldworks object has been instantiated by the program. Our programrequires that the SolidWorks session be closed at the end ofprogram execution. I've created a method to do just that:

 

privatestatic readonly log4net.ILog log =log4net.LogManager.GetLogger(typeof(ModuleAssembler));

       public void SWCleanup()

       {

 

           Process[] swRunning= Process.GetProcessesByName("SLDWORKS");

           Process swProcess;

           int swProcesses =swRunning.Length;

           if (swProcesses >0)

           {

               log.Debug(swProcesses.ToString() + " SolidWorks processesrunning.");

               for (int i = 0; i

               {

                   swProcess = swRunning[j];

                   swProcess.Kill();

               }

               int killed =swProcesses;

               log.Debug(killed.ToString() + " SolidWorks processeskilled.");

           }

       }

 

This is not a very pretty way to do things andresults in the temp files lying about.

So, the question is: How can I startSolidWorks, run the program, then gracefully close SolidWorkswithout an execution-style murder of the process?

 

BTW, the 'log' object is part of the loggerwe're using. I highly recommend this for anyone looking to create alog as the program executes. Go to http://logging.apache.org/log4net/

 

SolidworksApi macros