locked
Question on premature finalization of a managed object that is in use. RRS feed

  • Question

  •     
    1 >I am performing an operation on a C# object that is essentially a wrapper on an ummanaged object in my process space (Query object)
    2 >An operation on the managed object is invoked (Query.Execute) when I find that the Query object is being finalized by the .NET runtime while Execute is still in progress.
    3 >Object gets finalized, causing the underlying unmanaged object to become corrupt and throw an access violation 

    Does anyone here know of any issues that can explain this behavior and/or suggest workarounds

    thanks in advance
     
    Monday, November 10, 2008 6:36 PM

Answers

  • Hello,

    You need to use GC.KeepAlive method to prevent your object from being finalized.

    Vitaliy Liptchinsky
    Monday, November 10, 2008 6:50 PM

All replies