M
mind_the_gap
Hi,
i recently red a blog entry (http://blogs.msdn.com/bclteam/archive/
2005/03/16/396900.aspx) which stated that the use of IntPtr's holding
a reference to unmanaged resources could be dangerous in case of
object finalization and exceptions.
As I understood it the handle finalizer thread (it seems that there is
one and I can not change this) could run the objects finalizer, maybe
clean up the unmanaged resources (I do this in finanizers) and make
the IntPtr invalid. All this could happen while one is actually in a
unmanaged method and could lead to problems.
Since I use a lot of P/Invoke calls and do stuff on the unamanged side
I looked for solutions. A solution is the use of SafeHandles -
unfortunately this class/interface is not available in .Net CF. So
can't this problem occur in the compact framework or do I have to use
another solution (of which I do not know)?
It seems that this issue is critical if one uses P/Invokes in objects
that are not kept outside the local scope and in case of exceptions.
What do you think about this?
Thank you in advance,
Tom
i recently red a blog entry (http://blogs.msdn.com/bclteam/archive/
2005/03/16/396900.aspx) which stated that the use of IntPtr's holding
a reference to unmanaged resources could be dangerous in case of
object finalization and exceptions.
As I understood it the handle finalizer thread (it seems that there is
one and I can not change this) could run the objects finalizer, maybe
clean up the unmanaged resources (I do this in finanizers) and make
the IntPtr invalid. All this could happen while one is actually in a
unmanaged method and could lead to problems.
Since I use a lot of P/Invoke calls and do stuff on the unamanged side
I looked for solutions. A solution is the use of SafeHandles -
unfortunately this class/interface is not available in .Net CF. So
can't this problem occur in the compact framework or do I have to use
another solution (of which I do not know)?
It seems that this issue is critical if one uses P/Invokes in objects
that are not kept outside the local scope and in case of exceptions.
What do you think about this?
Thank you in advance,
Tom