none
Charting and garbage collector RRS feed

  • Question

  • Hi group, I have experienced something special that I would like to share and ask for your opinion on.

    Automation in PowerPoint to update charts. VSTO project. 

    I have code to update a PowerPoint's chart by scripting. But the problem was the remaining of Excel processes in the task manager, after execution. 1 excel process per chart in the presentation.

    I have pinpointed the problem. 

    Orginally I had this code:

      Private Sub updatechart(ByRef sh As PowerPoint.Shape)
        Dim oChart As PowerPoint.Chart
        Dim wb As Microsoft.Office.Interop.Excel.Workbook
        Dim ws As Microsoft.Office.Interop.Excel.Worksheet
        oChart = sh.Chart
        wb = oChart.ChartData.Workbook
        ws = wb.Worksheets(1)

     '.... here are updates on cells.

        wb.Application.Quit()


        System.Runtime.InteropServices.Marshal.ReleaseComObject(ws)
        System.Runtime.InteropServices.Marshal.ReleaseComObject(wb)
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oChart)

        ws = Nothing
        wb = Nothing
        oChart = Nothing


        Try
          GC.Collect()
          GC.WaitForPendingFinalizers()
          GC.Collect()
          GC.WaitForPendingFinalizers()
        Catch ex As Exception
        End Try
      End Sub

    This code worked fine for the update, but left my excel.exe process running. After several tests (and hours), I've found out that when I would remove the Try Catch End Try around the garbage collector, then the excel.exe process as execited correctly and I don't see Excel ghost processes anymore.

    What is happening here? 

    Friday, October 13, 2017 1:03 PM

All replies

  • Hello,

    The code doesn't work for me. Excel would keep running.

    Please use wb.Close() to close the Excel workbook instead.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 16, 2017 6:29 AM
    Moderator