Good day VB.Net seniors and experts,
I have a window service application which will import data from Excel file.
I face a problem
where Excel.exe process cannot be released from memory once the application
finish process an
Excel file. I did put the code to dereference those Excel objects being
created but seem like
the code is not working. Some portion of my code is shown as follows:
------------------------------------------------------------------------------
Imports System.Runtime.InteropServices.Marshal
Public oExcel As Object
Public oBook2 As Object
Public oSheet As Object
Try
oExcel = CreateObject("Excel.Application")
oBook2 = oExcel.Workbooks.Open(Path, 0)
oExcel.GoTo(Reference:="TCell")
oSheet = oBook2.ActiveSheet
// Grab required data from Excel Sheet
Catch err as Exception
// Log to event log and set "MoveToError" flag as TRUE
Finally
ReleaseComObject(oSheet)
oSheet = Nothing
oBook2.Saved = True
oBook2.Close()
ReleaseComObject(oBook2)
oBook2 = Nothing
oExcel.Quit()
ReleaseComObject(oExcel)
oExcel = Nothing
// Move the Excel file to "Error" folder if "MoveToError" flag is TRUE
End Tr
--------------------------------------------------------------------------------
Any idea why I can't terminate the Excel.exe process? The process is still
shown in Task
Manager.
Thanks a lot