Windows Develop Bookmark and Share   
 index > Windows Forms General > how to clear an excel object from the processes
 

how to clear an excel object from the processes

I am opening an xls file then closing and quit and set to nothing but it is still showing in my processes and cause errors saying the if i try to read more the 3 xls (not at the same time) some times is clears when I close the vb.net app but not always.

how can I clear the xls from memory?

xlsWB.Close()

xlsApp.Quit()

GC.Collect()

GC.WaitForPendingFinalizers()

Ljhopkins  Tuesday, March 13, 2007 9:14 PM

Hi , before you use GC to clear object ,you need to make sure no instance is in using, so you can add follow

System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheets);
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
...
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
System.Runtime.InteropServices.Marshal.ReleaseComObject(range);
worksheets=null;
worksheet=null;
...
excelApp=null;
range=null;

GC.Collect();

Bob zhu - SJTU  Wednesday, March 14, 2007 3:06 AM

still seeing an open excel in my processes this is what i tried

xlsWB.Close()

xlsApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsSheet)

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsWB)

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsApp)

xlsWB = Nothing

xlsApp = Nothing

xlsSheet = Nothing

GC.Collect()

GC.WaitForPendingFinalizers()

GC.Collect()

GC.WaitForPendingFinalizers()

And also Tried this

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsSheet)

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsWB)

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsApp)

xlsWB = Nothing

xlsApp = Nothing

xlsSheet = Nothing

GC.Collect()

GC.WaitForPendingFinalizers()

GC.Collect()

GC.WaitForPendingFinalizers()

Ljhopkins  Wednesday, March 14, 2007 1:35 PM

You can use google to search for other answers

Custom Search

More Threads

• MeasureCharacterRanges very slow when printing
• OnMouseDown problem
• MDI mergeing owner drawmenu
• getasynckeystate() example
• Help with Excel - Searching across multiple sheets
• .Net Active X controls embedded in internet explorer - security considerations
• Determining the form clicking
• Unload Application
• Oracle connection in WinForms Smart Client
• Creating line/character info on status bar