SW crashes after closing an assembly document

Hi all,

I'm working on C# application which imports geometry from SW files in background mode using API. Sometimes SW crashes when I close a document. It happens on large assemblies (assembly file is about 20 MB) very often.

1. I'm starting SW application

     swApp = new SW.SldWorksClass();

2. Put it into background mode

     swApp.UserControlBackground = true;
     swApp.UserControl = false;

3. Open document

     swDoc = swApp.OpenDoc7()

4. Walk through all bodies and get their geometry using ITesselation interface.

5. Close the document

     swApp.QuitDoc(swDoc.GetTitle());

6. Release a reference to SW application

     swApp = null;

I don't call swApp.ExitApp() because if SW is running in background mode and the only document is open - SW application must be closed automatically when I close the document (from help documentation on QuitDoc() method).

But if SW application doesn't crash it continues running.

Afterwards SW crashes and displays dialog box which asks about restarting SW application.

Please, help me to solve this problem.

Thanks in advance

-Vlad

SolidworksApi macros