C
chuckie_9497
hello all you gurus. I am struggling with releasing com objects. I
have isolated the problem to the code below. Objects are released and
the process ends until I
use "int k = sheet.Count;" Then the process does not end. So I feel
confident the problem occurrs here. It appears another reference is
created that needs to be closed. Can anyone tell me how to do
this?
Thank you
Excel.Workbook workbook =
(Excel.Workbook)excelapplication.ActiveWorkbook;
Excel.Sheets sheet = workbook.Worksheets;
// problem here
int k = sheet.Count;
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
sheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
workbook = null;
have isolated the problem to the code below. Objects are released and
the process ends until I
use "int k = sheet.Count;" Then the process does not end. So I feel
confident the problem occurrs here. It appears another reference is
created that needs to be closed. Can anyone tell me how to do
this?
Thank you
Excel.Workbook workbook =
(Excel.Workbook)excelapplication.ActiveWorkbook;
Excel.Sheets sheet = workbook.Worksheets;
// problem here
int k = sheet.Count;
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
sheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
workbook = null;