I'm trying to implement a sing开发者_开发技巧leton class, that holds a com object inside it. Class implements IDisposable interface, but when I try to implement a finalization method, I get an exception of access to com object from another thread.
This happens because clr uses a different thread when finalizes objects.
Is there any way to implement such a thing or maybe I just doing something wrong?
You only need to implement a finalizer if the class diectly manages the non-managed resource. A COM object is wrapped in a RCW (runtime callable wrapper), so there is already a managed type between your type and the COM interface pointer.
精彩评论