locked
releasing Excel process from memory RRS feed

  • Question

  • User1526558657 posted

    Hello,

    I'm using the following for reading an Excel file

    Microsoft.Office.Interop.Excel;

    System.Runtime.InteropServices;


    protected void btnReadExcel_Click(object sender, EventArgs e)
            {
    
                string Path = @"C:\test.xlsx";
                Application _excelApp = new Application();
    
                try
                {
                    Workbook workbook = _excelApp.Workbooks.Open(Path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                 
                    ExcelScanIntenal(workbook);
    
                    //clean up
                    workbook.Close(false, Path, null);
                    Marshal.ReleaseComObject(workbook);
                    
                }
                catch
                {
                    //...........
                }
            }


    my problem is that the Excel.EXE processes is hanging on... and still appears in task manager.

    also tried  Marshal.ReleaseComObject(_excelApp ) with no success.

    How do I make sure the Excel process is closed?


    thanks


    Sunday, January 2, 2011 9:09 AM

Answers

  • User197322208 posted

    It's not enough. You should still make the same with _excelApp  and to all references( and take care : range r = ...; r.Font.Bold = true - means assigning a new var to r.font and release those)...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 2, 2011 9:15 AM

All replies

  • User197322208 posted

    It's not enough. You should still make the same with _excelApp  and to all references( and take care : range r = ...; r.Font.Bold = true - means assigning a new var to r.font and release those)...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 2, 2011 9:15 AM
  • User1526558657 posted

    no need. I got it, thanks

    Sunday, January 2, 2011 2:15 PM