G
Guest
Hi,
I wrote an application that creates Excel objects in the background. I would
like to dispose these objects once I know they won't be used again.
I call the Excel quit function, and the objects stay there until the creator
application is closed. I also tried calling GC.Collect to force collection
with same results.
Sample code:
private void ExcelObjs()
{
Excel.ApplicationClass oXlApp = new Excel.ApplicationClass();
Excel.Workbook oBook = null;
oBook = oXlApp.Workbooks.Open(sFile,Type.Missing, false, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
true, true, Type.Missing, Type.Missing);
// Additional code here
if (oBook is Excel.Workbook)
oBook.Close(false,Type.Missing,Type.Missing);
// Tried calling GC.Collect to force garbagge collection
int nGeneration = GC.GetGeneration(oXlApp);
oXlApp.Quit();
GC.Collect(nGeneration);
}
I will appreciate any help.
Carlos
I wrote an application that creates Excel objects in the background. I would
like to dispose these objects once I know they won't be used again.
I call the Excel quit function, and the objects stay there until the creator
application is closed. I also tried calling GC.Collect to force collection
with same results.
Sample code:
private void ExcelObjs()
{
Excel.ApplicationClass oXlApp = new Excel.ApplicationClass();
Excel.Workbook oBook = null;
oBook = oXlApp.Workbooks.Open(sFile,Type.Missing, false, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
true, true, Type.Missing, Type.Missing);
// Additional code here
if (oBook is Excel.Workbook)
oBook.Close(false,Type.Missing,Type.Missing);
// Tried calling GC.Collect to force garbagge collection
int nGeneration = GC.GetGeneration(oXlApp);
oXlApp.Quit();
GC.Collect(nGeneration);
}
I will appreciate any help.
Carlos