The following code sample worked just fine in Excel 2007, but when I installed Excel 2010 (32bit) it would leave the excel.exe process open unless I added the GC.Collect(). My simple question is am I doing something wrong? It looks like to me like I am releasing everything I use.
public override void Update()
{
StatusBox.AddStatus("Opening File " + ImportPath);
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Open(ImportPath, 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);
Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Sheets[1];
Range rng = ws.Cells.SpecialCells(XlCellType.xlCellTypeLastCell, Type.Missing);
int LastRow = rng.Row;
StatusBox.AddStatus(LastRow.ToString() + " Rows Found in File");
StatusBox.AddStatus("Closing File " + ImportPath);
System.Runtime.InteropServices.Marshal.ReleaseComObject(rng);
rng = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
ws = null;
wb.Close(true, ImportPath, null);
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
wb = null;
GC.Collect();
app.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
app = null;
}