SEHException Exception from a COM component

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???
 
J

Jason Newell

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
 
G

Guest

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.
 
J

Jason Newell

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top