开发者

Finalizing a COM object

开发者 https://www.devze.com 2023-01-01 11:14 出处:网络
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 except

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消