Mr.Orange
March 30th, 2004, 04:05 PM
I'm trying to figure out the exact cause of an error I am getting and I was hoping someone could point me in the right direction.
The error I get is as follows:
Error # 5 was generated by Interop.Excel - COM object that has been separated from its underlying RCW can not be used.
The COM object I am using is the MS Excel 10.0 Object Library.
I create the following types of objects using this COM object:
Excel.Application
Excel.Workbook
Excel.Worksheet
Excel.ChartObjects
Excel.ChartObject
Excel.Chart
Excel.Range
Excel.Series
I use these objects to access, modify and manipulate data in an Excel spreadsheet.
i.e.
XL_App = CType(CreateObject("Excel.Application"), Excel.Application)
XL_Book = XL_App.Workbooks.Open(STORAGE_DIRECTORY & "Spreadsheets\" & XL_File_Name & ".xls")
XL_Sheet = CType(XL_Book.Worksheets(1), Excel.Worksheet)
and so on...
My problem seems to be related to the fact that I use these objects in threads that I create using System.Threading.Thread.
Sometimes I seem to be able to get away with using these objects in threads and sometime I don't. A specific instance I have found that seems to cause problems is when I use these objects in a thread that calls Application.DoEvents().
I have tried using GC.KeepAlive on all of the Excel objects.
I don't want to make this post too long, so I'm just going to leave it at that. I'm just hoping that someone has some general advice they could give me on this issue.
Thanks.
The error I get is as follows:
Error # 5 was generated by Interop.Excel - COM object that has been separated from its underlying RCW can not be used.
The COM object I am using is the MS Excel 10.0 Object Library.
I create the following types of objects using this COM object:
Excel.Application
Excel.Workbook
Excel.Worksheet
Excel.ChartObjects
Excel.ChartObject
Excel.Chart
Excel.Range
Excel.Series
I use these objects to access, modify and manipulate data in an Excel spreadsheet.
i.e.
XL_App = CType(CreateObject("Excel.Application"), Excel.Application)
XL_Book = XL_App.Workbooks.Open(STORAGE_DIRECTORY & "Spreadsheets\" & XL_File_Name & ".xls")
XL_Sheet = CType(XL_Book.Worksheets(1), Excel.Worksheet)
and so on...
My problem seems to be related to the fact that I use these objects in threads that I create using System.Threading.Thread.
Sometimes I seem to be able to get away with using these objects in threads and sometime I don't. A specific instance I have found that seems to cause problems is when I use these objects in a thread that calls Application.DoEvents().
I have tried using GC.KeepAlive on all of the Excel objects.
I don't want to make this post too long, so I'm just going to leave it at that. I'm just hoping that someone has some general advice they could give me on this issue.
Thanks.