Excel.exe is in not releasing from the Process List

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my web application(C#) . I am adding one excel sheet and then save and
closing that excel file. In the finally bloack i gave

Marshal.ReleaseComObject(clsExcel);

But when i go and see in the TaskManager --> Processes Tab its still having
that Excel.exe. If i opened more than one excel sheet and do these operations
then more than one Excel.exe is displaying in the list.

Please any one give me the solution for this issue.
 
| In my web application(C#) . I am adding one excel sheet and then save and
| closing that excel file. In the finally bloack i gave
|
| Marshal.ReleaseComObject(clsExcel);
|
| But when i go and see in the TaskManager --> Processes Tab its still
having
| that Excel.exe. If i opened more than one excel sheet and do these
operations
| then more than one Excel.exe is displaying in the list.
|
| Please any one give me the solution for this issue.

One solution is NOT to use Office applications in Web applications, read
this http://support.microsoft.com/default.aspx?scid=kb;en-us;257757 to know
why.

Willy.
 
B.N. Prabhu,

Well, you need to post more of your code in order for that to be
determined. However, it is more than likely that this is the result of you
not releasing all of the references to the objects that you are using.
Every object in Excel has a reference to the main Application, and you MUST
release all of those references when you use them.

The thing is, most people create references, and don't even know it.
Normally, they do this:

// Get a cell value. BTW, I dont expect this to compile, its to prove a
point.
object value = workbook.Worksheets.Item(1).Cells.Item(0, 0).Value;

The thing is, when you call Workbooks, you are exposing an object which
has a reference to application, but then it goes out of scope, and you have
to wait for a GC to release the reference. What you need to do is this:

// Again, won't compile, but you get the idea.
object worksheets = workbook.Worksheets;
object worksheet = worksheets.Item(1);
object cells = worksheets.Cells;
object cell = cells.Item(0, 0);
object value = cell.Value;

// Release everything.
Marshal.ReleaseComObject(cell);
Marshal.ReleaseComObject(cells);
Marshal.ReleaseComObject(worksheet);
Marshal.ReleaseComObject(worksheets)

This is what you have to do for pretty much every object reference in
Excel.

Of course, what you could do is assuming you have released all the
references (to the Runtime Callable Wrappers), you could just call
GC.Collect to force the release of the wrappers, which would force the
release of the COM object, and then your app should end as well.

BTW, Willy is correct in that you shouldn't really be using Excel in web
applications.

Hope his helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top