I recently finished writing a routine to apply processing to an Excel file through VB.NET using the automation API. The code works fine, and it is called repeatedly for about 60 work items. In other words, about 60 reports are being rendered from rdlc to Excel, and then those 60 files are processed one by one using this routine.
At about the 60% or 70% mark during processing, which is usually between 15 and 20 minutes into the process, the following exception is thrown:
DisconnectedContext was detected
Message: Context 0x198388' is disconnected. Releasing the interfaces from the current context (context 0x1984f8).This may cause corruption or data loss. To avoid this problem, please ensure that all contexts/apartments stay alive until the applicationis completely done with the RuntimeCallableWrappers that represent COM components that liveinside them.
I am not a COM expert, and it sounds like this is a COM error. I am only using COM to the extent needed to make use of Excel automation.
What is this exception, and how can I keep this from happening until all of the processing is complete?