SEHException Exception from a COM component

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a COM based component that raises an exception and I'm awaiting a
patch for it. However, I need to be able to recover from the exception,
destroy the COM object and then regenerate it @ a later date in my C# Windows
Forms App.

I presently do this:

System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
System.GC.Collect(0);

However, it is not fully releasing the object

Any thoughts???
 
cneff78,
Give this a try.


while (System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) > 0);
obj = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();

Jason Newell, MCAD
Software Engineer
 
Thank you for your quick reply

I implemented the code snippet you sent me but I'm still getting the same
error. However, I can see where what you were doing in your snippet was a
better handling of the COM clean-up. Thanks again for your help.
 
cneff78,
Where does the exception get thrown? Obviously you cannot prevent the
exception but you can control how you deal with it by using
try...catch...finally... block.
How are you validating that the COM object is not getting released? Are
you able to recreate the object once it has thrown the exception.
You might get more answers with a little more detail.

Jason Newell, MCAD
Software Engineer
 
Back
Top