How can I kill an "Excel" process from a memory?

M

Michael Tkachev

Hi Everybody,

I created an Excel file in the ASP.Net. When I wrote this file on the disk I
tryed to release COM objects. But I couldn't do it. When my method finished
an "Excel" process exists in the memory. So, I would like to kill an
"Excel" process and for it I need to know a ProcessID or something like
this. Who knows how can I get a processID or release COM objects?


Excel.ApplicationClass a = new Excel.ApplicationClass();

.... // Here lies my code.

a.Quit();
while(System.Runtime.InteropServices.Marshal.ReleaseComObject(eRange) == 0);
while(System.Runtime.InteropServices.Marshal.ReleaseComObject(_Worksheet) ==
0);
while(System.Runtime.InteropServices.Marshal.ReleaseComObject(_Workbook) ==
0);
while(System.Runtime.InteropServices.Marshal.ReleaseComObject(a) == 0);

_Worksheet = null;
eRange = null;
_Workbook = null;
a = null;

// Process[] p = Process.GetProcessesByName("EXCEL");
// foreach(Process pp in p)
// {
// pp.Kill();
// pp.Close();
// pp.Dispose();
// }

Thank you very much.
 
G

Guest

Hi Michael,

First of all, there's no way that you can differentiate excel instantances
on memory if there's more than one instance active at the same time, (which
happens if there are two people trying to create an excel report) so you
would need to keep time stamps etc etc. My suggestion; screw this method.

Better way is to find why there's still an excel instance hanging on the
memory. This usually happens because of the COM Wrapper. We had such a
discussion before; take a look at this entry;

http://msdn.microsoft.com/newsgroup...pnet&mid=6c573870-bff7-4915-8c42-630dc6d0b8c5

or search for "writting excel files" on this group.

Hope this helps,

Ethem Azun
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top