Excel staying in Task Manager in ASP.NET

tylee

New member
Joined
Jun 3, 2003
Messages
3
Hi

I have a .net project written in vb.net and i am having a problem killing ALL instances of the excel process in the task manager. I had this problem with a windows service written in vb.net but I have managed to fix that problem but the same code doesnt fix the problem I am having in my website

The Code:

Dim exObj As New Excel.Application()
Dim exWorksheet As Excel.Worksheet
Dim exWorkbook As Excel.Workbook

exWorkbook = exObj.Workbooks.Open(("Template.xlt")
exWorksheet = exWorkbook.Worksheets(1)

Code in here which writes to the excel file and saves it for furture use


attempts to close the excel process

exWorkbook.Close()
exObj.Workbooks.Close()
exObj.Application.Quit()
exObj.Quit()

exWorksheet = Nothing
exWorkbook = Nothing
exObj = Nothing

GC.Collect()
GC.WaitForPendingFinalizers()


if anyone can help it would be much appreciated
 
Last edited by a moderator:
Here is my working code which opens the file, changes it and saves it. I finally got it to destroy the process with the help of the previous post.

Code:
Dim MyExcel As New Excel.Application()
        Dim oWorkbooks As Excel.Workbooks = MyExcel.Workbooks
        Dim theWorkbook As Excel.Workbook = oWorkbooks.Add
        Dim oSheet As Excel.Worksheet

        theWorkbook = oWorkbooks.Open("C:\TEST.xls")

        oSheet = MyExcel.ActiveSheet()

ALTER THE WORKSHEET HERE
       


        theWorkbook.Save()

        theWorkbook.Close()
      
        MyExcel.Quit()

        oSheet = Nothing
        theWorkbook = Nothing
        oWorkbooks = Nothing
        MyExcel = Nothing

        GC.Collect()
        GC.WaitForPendingFinalizers()
 
Ive been having the same problem with Excel hanging processes. I copied and pasted the exact code below and it still hangs the process. Ive also tried working with the "Process" object, but I get an Access denied error. Any ideas? This is holding up my project big time....
 
Following should work:

Code:
MyExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(MyExcel);
MyExcel = null;

But you have to do this with all your little objects (like Excel.Range, Excel.Cell etc.) When you clean all this objects, your Excel process should end. Woked for me fine!!!

Regards,
Stefan
 
I agree that this works in a VB.net application, but I cant seem to get it to work in ASP.net. Would there be any difference with that?
 
Back
Top