EDrawings Batch Print Macro caused crash

Hello!

I have written an simple Macro in Visual Studio 2010 Express to batch Print Drawings from our Workgroup PDM Vault.

We use SolidWorks 2011 SP5

If i will Printing 75 drawings the Application crash after printing about 50 drawings: "vshost32.exe funktioniert nicht mehr" (vshost32.exe has stopped working)

Problemsignatur:

Problemereignisname: APPCRASH

Anwendungsname: BatchPrint Beispiel.vshost.exe

Anwendungsversion: 10.0.30319.1

Anwendungszeitstempel: 4ba2084b

Fehlermodulname: EModelView.dll

Fehlermodulversion: 11.5.0.111

Fehlermodulzeitstempel: 4e726112

Ausnahmecode: c0000005

Ausnahmeoffset: 00079544

Betriebsystemversion: 6.1.7601.2.1.0.256.48

Gebietsschema-ID: 1031

Zusatzinformation 1: 426c

Zusatzinformation 2: 426cfe4a599aa1abcb3fcd86b4c6dc3b

Zusatzinformation 3: 32c3

Zusatzinformation 4: 32c3a3e1308a471fe77338eebb6ec92d

I have tested several times, and it stops working from time to time on different documents.

I have also tested with only one Form and without disposing...exactly the same.

I have tested it on several computers...

Here is the source code (how can i insert code formated?):

Form1 (with a DataGridView and a Button)

[code]

Imports System.IO
Imports System.Runtime.InteropServices

Public Class Form1
    Dim connection As PDMWorks.PDMWConnection
    Dim TempPath As String = Path.Combine(Path.GetTempPath, "BatchPrint")

    Public Shared FinishedLoading As Boolean = False
    Public Shared FailedLoad As Boolean = False
    Public Shared FinishedPrinting As Boolean = False
    Public Shared FailedPrinting As Boolean = False

    _
    Public Shared Function SetProcessWorkingSetSize(process As IntPtr, minimumWorkingSetSize As Integer, maximumWorkingSetSize As Integer) As Integer
    End Function

    Private Sub BtnStart_Click(sender As System.Object, e As System.EventArgs) Handles BtnStart.Click

        For i As Integer = 0 To DataGridView1.Rows.Count - 1

            'Leere zeilen überspringen
            If DataGridView1.Rows(i).Cells(0).FormattedValue.trim = "" Then
                Continue For
            End If

            'Dokument aus Tresor holen
            Dim doc As PDMWorks.PDMWDocument
            doc = connection.GetSpecificDocument(DataGridView1.Rows(i).Cells(0).FormattedValue)
            Debug.WriteLine(doc.Name)

            'Dokument temporär speichern
            doc.Save(TempPath)

            'In Edrawings laden
            Dim f As New Form2
            'f.Show()
            f.AxEModelViewControl1.OpenDoc(Path.Combine(TempPath, doc.Name), False, False, False, "")

            'Warten, bis Dokument geladen wurde
            Do Until FinishedLoading = True
                Application.DoEvents()
                System.Threading.Thread.Sleep(50)
                If FailedLoad = True Then
                    MsgBox(doc.Name & " konnte nicht geöffnet werden!", MsgBoxStyle.Critical)
                    FailedLoad = False
                    Continue For
                End If
            Loop
            FinishedLoading = False

            'Set Options
            If f.AxEModelViewControl1.SheetHeight > f.AxEModelViewControl1.SheetWidth Then
                f.AxEModelViewControl1.SetPageSetupOptions(EModelView.EMVPrintOrientation.ePortrait, 9, 0, 0, _
                                                             1, 7, "PDF24 PDF", 0, 0, 0, 0)
            Else
                f.AxEModelViewControl1.SetPageSetupOptions(EModelView.EMVPrintOrientation.eLandscape, 9, 0, 0, _
                                                         1, 7, "PDF24 PDF", 0, 0, 0, 0)
            End If

            'Print
            f.AxEModelViewControl1.Print4(False, doc.Name, False, False, False, 1, 0, 0, 0, True, 0, 0)

            'Wait for finished printing
            Do Until FinishedPrinting = True
                Application.DoEvents()
                System.Threading.Thread.Sleep(50)
                If FailedPrinting = True Then
                    MsgBox(doc.Name & " konnte nicht gedruckt werden!", MsgBoxStyle.Critical)
                    FailedPrinting = False
                    Continue For
                End If
            Loop
            FinishedPrinting = False

            'Close Document
            f.AxEModelViewControl1.CloseActiveDoc("")
            Do Until f.AxEModelViewControl1.SheetCount = 0
                System.Threading.Thread.Sleep(100)
                Application.DoEvents()
            Loop

            f.Dispose()
            f = Nothing

            'to reduce memory using
            GC.Collect()
            GC.WaitForPendingFinalizers()
            If Environment.OSVersion.Platform = PlatformID.Win32NT Then
                SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
            End If

           

        Next

    End Sub

    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        connection = CreateObject("PDMWorks.PDMWConnection")
        connection.Login("pdmwadmin", "pdmwadmin", "hmtechv")

        'Temppath anlegen
        System.IO.Directory.CreateDirectory(TempPath)

    End Sub

   

     Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs)

     End Sub
End Class

[/code]

And Form2 (with the EDrawings Control)

[code]

Public Class Form2


    Private Sub AxEModelViewControl1_OnFailedLoadingDocument(sender As Object, e As AxEModelView._IEModelViewControlEvents_OnFailedLoadingDocumentEvent) Handles AxEModelViewControl1.OnFailedLoadingDocument
        Form1.FailedLoad = True
    End Sub

    Private Sub AxEModelViewControl1_OnFailedPrintingDocument(sender As Object, e As AxEModelView._IEModelViewControlEvents_OnFailedPrintingDocumentEvent) Handles AxEModelViewControl1.OnFailedPrintingDocument
        Form1.FailedPrinting = True
    End Sub

    Private Sub AxEModelViewControl1_OnFinishedLoadingDocument(sender As Object, e As AxEModelView._IEModelViewControlEvents_OnFinishedLoadingDocumentEvent) Handles AxEModelViewControl1.OnFinishedLoadingDocument
        Form1.FinishedLoading = True
    End Sub

    Private Sub AxEModelViewControl1_OnFinishedPrintingDocument(sender As Object, e As AxEModelView._IEModelViewControlEvents_OnFinishedPrintingDocumentEvent) Handles AxEModelViewControl1.OnFinishedPrintingDocument
        Form1.FinishedPrinting = True
    End Sub
End Class

[/code]

I have also add the Projekt as Zip.

What can i do? Have i made a fault?

Regards

Sascha

SolidworksApi macros