Defining a delegate as a function pointer

后端 未结 1 912
臣服心动
臣服心动 2021-01-13 07:00

I am using a delegate which calls an unmanaged function pointer. This causes the Garbage Collector to collect it before it is used, as described in the CallbackOnCollectedDe

相关标签:
1条回答
  • 2021-01-13 07:09

    You didn't read it correctly. You must do this:

    ...change your code to keep a reference to that delegate on the managed side for the lifetime of the marshaled unmanaged function pointer.

    In other words, just store a reference to the delegate instance in your class and make sure the class object survives long enough. Use a static if you really have to.

    0 讨论(0)
提交回复
热议问题