Hi, I have a problem with hanging excel processes. My applications gets data from the database and populates a excel spreadsheet however all is well untill I view the task manager to find the EXCEL.EXE still running. I've managed to solve it by calling the GC.Collect method but I think thats quite a brute method to do it, is there a more elegant way of doing this?
my code is shown below.
Excel.ApplicationClass app = new ApplicationClass();
app.Workbooks.Add(Missing.Value);
app.Cells[1, 1] = "First Name";
app.Visible = true;
Worksheet worksheet = (Worksheet)app.ActiveSheet;
worksheet.SaveAs(@"C:\test.xls",
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value);
app.Workbooks.Close();
app.Quit();
Marshal.ReleaseComObject(app);
Marshal.ReleaseComObject(worksheet);
app = null;
worksheet = null;
GC.Collect(); -- DONT WANT TO DO THIS
my code is shown below.
Excel.ApplicationClass app = new ApplicationClass();
app.Workbooks.Add(Missing.Value);
app.Cells[1, 1] = "First Name";
app.Visible = true;
Worksheet worksheet = (Worksheet)app.ActiveSheet;
worksheet.SaveAs(@"C:\test.xls",
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value);
app.Workbooks.Close();
app.Quit();
Marshal.ReleaseComObject(app);
Marshal.ReleaseComObject(worksheet);
app = null;
worksheet = null;
GC.Collect(); -- DONT WANT TO DO THIS