Everytime I run this code, the object won't close. I still have an excel.exe running in the task manager. Even if I set the objects = null, still nothing. I've even tried using the objects .Quit() method.
What am I doing wrong here?
private bool ValidateQM()
{
//setup the objects
Excel.Application oXL = null;
Excel.Workbook oWB = null;
Excel.Worksheet oSheet = null;
int hWnd = 0;
try
{
//Start Excel and get Application object.
oXL = new Excel.Application();
hWnd = oXL.Application.Hwnd;
oXL.Visible = false;
//Open the workbook.
oWB = oXL.Workbooks.Open(workingForm, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",true, false, 0, true, false, false);
//Get the Worksheet
oSheet = oWB.Worksheets[1];
//Check the date values
string mydatetime = oSheet.Cells[5, 33].Text.ToString() + " " + oSheet.Cells[7, 33].Text.ToString();
string dateofscore = oSheet.Cells[3, 12].Text.ToString();
DateTime.Parse(mydatetime); //make my string a real boy
DateTime.Parse(dateofscore);
// Cleanup
GC.Collect();
GC.WaitForPendingFinalizers();
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oSheet);
//oWB.Close();
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oWB);
//oXL.Quit();
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oXL);
return true;
}