Click here to Skip to main content
12,297,983 members (55,539 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
public void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Excel File|*.xls|Excel File|*.xlsx";
            
            openFileDialog1.ShowDialog();
            
            string path = openFileDialog1.FileName;
            
            comboBox1.Items.Clear();
 
            Microsoft.Office.Interop.Excel.Application xlr = new            
            Microsoft.Office.Interop.Excel.Application();
 
            Workbook wb = xlr.Workbooks.Open(path, 0, false, 5, "", "", false, 
            XlPlatform.xlWindows, "", true, false, 0, true, false, false);
 
            foreach (Worksheet w in xlr.Worksheets)
            {
                comboBox1.Items.Add(w.Name);
            }
 
            xlr.Visible = true;
 
            wb.Close();
            xlr.Quit();
 
            System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlr);
 
        }


How can i safely dispose off/Release Excel COM objects in the above code??
Even after releasing in the above fashion i see that excel is running in the task manager under processes ...?
Posted 25-Dec-12 12:02pm
Edited 25-Dec-12 12:05pm
v2
Comments
austinbox 25-Dec-12 20:01pm
   
After releasing the com object, you could try killing the process...

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 26 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100