Excel Class - Need to be Finalized

Arch4ngel

Well-known member
Joined
Mar 22, 2004
Messages
940
Location
Montreal, QC
I have a class that is a bridge between Excel Interop and my interface. (See attachment).

What I do... is I read a report with Excel. The first line is Headers and all non-empty line are data.

The server must not keep Excel open. I must close Excel as soon as I have finished using it. Other application on the server might open other instance of Excel (so no process killing maniac please [Broken External Image]:http://www.computerhelp.forum/images/smilies/tongue.gif)

What Ive seen... its that Excel.exe is closed when I call GC.Collect() but its really poor .NET practice to do that... so Im searching a smarter way of doing the same result.


Thank you.

N.B. : The class is in C#. Some comments are in french, sorry. But the code is still understandable.
 

Attachments

Forgot to tell you the how it was called :

C#:
CExcel excel = new CExcel("Some right file name.xls");
 excel.GetRow(....);
 //....some other code here
 excel.Dispose();
 excel = null;
 
Well... Excel run on an ASP.NET application. Sorry for the misunderstanding.
It was my fault. And if you downloaded my CExcel class... youll see that .Dispose() do this. (m_app.Quit())
 
well. . .

xlApp.UserControl = false;
xlApp.Quit();


should release it if it is the last reference.

xlApp.UserControl = true;
xlApp.Quit();


would leave it available.
 
Well... I tryed it and its still on the Task Manager of my computer ( server and client... well... developpement machine you know).

Ill try some few things but... if you can help me on this one... I would really appreciate it.
 
Well... it didnt work but I convince myself to use GC.Collect() even if I know its a really bad practice until I find something thatll work better than that.
 
Hi guys,

Per se it should be handled by the Garbage Collector and per se the Garbage Collector should not be initiated in code.

Unlike VB 6.0 VB.NET does not immedately release the COM-object when its set to nothing which means that we dont know when its released...Yes, when You
 
Well... if you downloaded my class... youve probably seen that ive already done all of that. Excel is ready to be closed. It just... dont close. Why ? Because when I active the garbage collector... it disapear from the task manager.

Well... currently I use GC.Collect(); but... if someone have a way to close Excel right when I need it to be closed... then... thank you !

I have a beginning of an Idea that is running through my head.... Excel is a process no ? Might I simply kill it ? Is there a way to get the handle of excel to make sure Ive closed the right one ? Someone can help me on this one ? Ive never used any Process object.

Thank you very much
 
this is wierd. . .

Using XL 2003 on .NET

PHP:
xl = new Excel.ApplicationClass();
xl.UserControl = false;
xl.Quit();
xl = null;
has left the Excel Process in memory now for 5 minutes. . .

The same Code, XL 2000, Delphi 7 sans .NET would remove the XL process at the xl.Quit() call. I dont have Office 2000 or Delphi 7 here at home, but I will try when I get to work in the morning. It might be a bug in XL 2003, but I doubt it. It could be a side effect of XL 2003 interopped in .NET.
 
running this vbs script agains Excel XP (not 2003 as I previously said) :
Code:
dim xl
set xl = CreateObject("Excel.Application")
MsgBox "Excel Created"
xl.UserControl = false
xl.Quit()
MsgBox "Excel Quit"
MsgBox "Now we will try to show it after quitting"
on error resume next
xl.visible = true
if err.number <> 0 then
MsgBox Err.description
else
MsgBox "Excel didnt really quit"
xl.visible = false
MsgBox "Excel is closed"
end if
set xl = nothing
MsgBox "Excel is Gone"
releases Excel at the set xl = nothing line.

thats funny as in Excel 2000 Delphi 7 no .NET i believe it was removed after the Quit call.

Again, I will check in the morning.
 
Yeah... you know exactly my problem. When I was working with Delphi 5 at school ... we were using OLE object to make some interop with Excel and Word. And as soon that all memory were released and that app.Quit was called... Excel or Word was closing.

But now in .NET you see that its not closed yet. The program will be running on a web server... so Excel really need to be closed. I dont want 10 version of Excel opened at the same time even if I know that the garbage collector will soon or later close all of them. I donT want to wait a Collect() before clearing them all.

Then I thinked about Process.... but I dont know if its "good programming" or anything. Will it be available from my web server (dont have admin rights... well... only ASPNET, IUSR have all access where it needs to. "Domains Users" have some rights too because its a "Integrated Security" application. Basic auth is used but donT worry... its only available locally.
 
Well... we solved the problem... well... kind of. LOL

We moved the application from Web side to client side. As it is an administrative task... we decided to make a single Client-side app so we dont have any more problem with Excel still being openned.

Thank you very much Joe Mamma for your precious time. It has been helpful.
 
Back
Top