How to force ExcellApp.Quit() when it's actually called?

  • Thread starter Thread starter sherifffruitfly
  • Start date Start date
S

sherifffruitfly

Hi,

I load the contents of an excel sheet into a dataset via the excel
object library (couldn't get the #$%#$^ oledb/ado route to work -
#^$%&^%$ connection strings... grrr.... )

Anyway, after I get the sheet's contents into my dataset, I'd love to
jettison excel. Calling ExcelApp.Quit() has no effect until I exit the
entire application. How can I force excelapp.quit() to take effect when
the line is executed?

thanks!

cdj
 
Hi cdj,

Are you operating Excel through Late Binding?

I had similar issues to the ones you describe and found that Marshall.ReleaseComObject did the trick.

Hope it helps

Stuart King
Informology Ltd.
 
Stuart said:
Hi cdj,

Are you operating Excel through Late Binding?

Hi Stuart -

Thanks for the reply.

My project's references to the Excel 11.0 object library are added
before I compile - I take it that's a "no" to your question?
 
Hi cdj,

I've tried the approach I gave you using the Microsoft Office
references(Early Binding) and in fact it still gives the desired effect. I
tried it out in a button click handler on a form. The following code does
nothing fancy, all it does is show Excel, waits for 5 seconds then quits
Excel again. If you use Task Manager you should be able to see the excel
process coming alve and then being unloaded from memory

private void button1_Click(object sender, EventArgs e)

{

Microsoft.Office.Interop.Excel.ApplicationClass App = new
Microsoft.Office.Interop.Excel.ApplicationClass();

App.Visible = true;

System.Threading.Thread.Sleep(5000);

App.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComObject(App);

}



Hope this helps.



Stuart King

Informology Ltd.
 
Stuart said:
System.Runtime.InteropServices.Marshal.ReleaseComObject(App);

That line (which I didn't understand the first time you mentioned it)
solved all problems.

Thanks a million!

cdj
 

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