Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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 13:02pm
Edited 25-Dec-12 13:05pm
v2
Comments
austinbox at 25-Dec-12 20:01pm
   
After releasing the com object, you could try killing the process...

1 solution

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

  Print Answers RSS
0 Maciej Los 199
1 Sergey Alexandrovich Kryukov 154
2 Sascha Lefévre 120
3 Abhinav S 104
4 Rana Waqas 78
0 Sergey Alexandrovich Kryukov 6,628
1 OriginalGriff 6,298
2 Peter Leow 2,534
3 Maciej Los 2,437
4 Abhinav S 2,378


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 26 Dec 2012
Copyright © CodeProject, 1999-2015
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